46
General discussions / Re: Multi monitor support
« on: September 17, 2015, 06:12:32 pm »
Alright! I implemented the change. The new commit can be found here.
Updated testing code:
It would be cool if someone with win7 or older could test this (even with 1 monitor) to see if the dpi is working correctly. Maybe also someone with a high dpi mointor. As always I am open for feedback
Updated testing code:
(click to show/hide)
#include <SFML/Window.hpp>
#include <iostream>
int main()
{
// query screen count
std::size_t totalMonitors = sf::Screen::count();
std::cout << "# of connected Screens: " << totalMonitors << std::endl;
// enumerate over all screens
for(std::size_t id = 0; id < totalMonitors; ++id)
{
sf::Screen screen = sf::Screen::get(id);
const std::vector<sf::VideoMode> modes = screen.fullscreenModes;
std::cout << "Valid resolutions for screen " << modes[0].screenId << std::endl << std::endl;
// fullscreen modes
for(std::size_t i = 0; i < modes.size(); ++i)
{
sf::VideoMode mode = modes[i];
std::cout << "Mode #" << i << ": "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl;
}
std::cout << std::endl;
// desktop mode
sf::VideoMode mode = screen.desktopMode;
std::cout << "Desktop mode for screen #" << id << ": "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl << std::endl;
// screen information
const sf::IntRect bounds = screen.bounds;
const sf::IntRect workingArea = screen.workingArea;
std::wcout << "Monitor " << screen.id << " name: " << screen.name << std::endl
<< "x: " << bounds.left << " y: " << bounds.top << " width: " << bounds.width << " height: " << bounds.height << std::endl
<< "x: " << workingArea.left << " y: " << workingArea.top << " width: " << workingArea.width << " height: " << workingArea.height << std::endl
<< "refreshRate: " << screen.refreshRate << "Hz"
<< " dpi: " << screen.dpi.x << "x" << screen.dpi.y << std::endl << std::endl << std::endl;
}
// backward compatibility with depreaction note
sf::VideoMode::getDesktopMode();
// open a fullscreen window on the second screen
sf::VideoMode videoMode(1024, 768, 32, 1);
sf::Window window(videoMode, "Multi Monitor Example!" , sf::Style::Fullscreen);
window.setFramerateLimit(sf::Screen::get(videoMode.screenId).refreshRate);
// run the program as long as the window is open
while (window.isOpen()) {
// check all the windows events
sf::Event event;
while (window.pollEvent(event)) {
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::KeyReleased) {
// close if escape key was pressed
if (event.key.code == sf::Keyboard::Escape) {
window.close();
}
if (event.key.code == sf::Keyboard::Return) {
window.create(videoMode, "Multi Monitor Example", sf::Style::Resize);
window.setFramerateLimit(sf::Screen::get(videoMode.screenId).refreshRate);
}
}
}
// display the windows content
window.display();
}
return 0;
}
#include <iostream>
int main()
{
// query screen count
std::size_t totalMonitors = sf::Screen::count();
std::cout << "# of connected Screens: " << totalMonitors << std::endl;
// enumerate over all screens
for(std::size_t id = 0; id < totalMonitors; ++id)
{
sf::Screen screen = sf::Screen::get(id);
const std::vector<sf::VideoMode> modes = screen.fullscreenModes;
std::cout << "Valid resolutions for screen " << modes[0].screenId << std::endl << std::endl;
// fullscreen modes
for(std::size_t i = 0; i < modes.size(); ++i)
{
sf::VideoMode mode = modes[i];
std::cout << "Mode #" << i << ": "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl;
}
std::cout << std::endl;
// desktop mode
sf::VideoMode mode = screen.desktopMode;
std::cout << "Desktop mode for screen #" << id << ": "
<< mode.width << "x" << mode.height << " - "
<< mode.bitsPerPixel << " bpp" << std::endl << std::endl;
// screen information
const sf::IntRect bounds = screen.bounds;
const sf::IntRect workingArea = screen.workingArea;
std::wcout << "Monitor " << screen.id << " name: " << screen.name << std::endl
<< "x: " << bounds.left << " y: " << bounds.top << " width: " << bounds.width << " height: " << bounds.height << std::endl
<< "x: " << workingArea.left << " y: " << workingArea.top << " width: " << workingArea.width << " height: " << workingArea.height << std::endl
<< "refreshRate: " << screen.refreshRate << "Hz"
<< " dpi: " << screen.dpi.x << "x" << screen.dpi.y << std::endl << std::endl << std::endl;
}
// backward compatibility with depreaction note
sf::VideoMode::getDesktopMode();
// open a fullscreen window on the second screen
sf::VideoMode videoMode(1024, 768, 32, 1);
sf::Window window(videoMode, "Multi Monitor Example!" , sf::Style::Fullscreen);
window.setFramerateLimit(sf::Screen::get(videoMode.screenId).refreshRate);
// run the program as long as the window is open
while (window.isOpen()) {
// check all the windows events
sf::Event event;
while (window.pollEvent(event)) {
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::KeyReleased) {
// close if escape key was pressed
if (event.key.code == sf::Keyboard::Escape) {
window.close();
}
if (event.key.code == sf::Keyboard::Return) {
window.create(videoMode, "Multi Monitor Example", sf::Style::Resize);
window.setFramerateLimit(sf::Screen::get(videoMode.screenId).refreshRate);
}
}
}
// display the windows content
window.display();
}
return 0;
}
It would be cool if someone with win7 or older could test this (even with 1 monitor) to see if the dpi is working correctly. Maybe also someone with a high dpi mointor. As always I am open for feedback