SFML community forums

Help => Window => Topic started by: underww on March 07, 2014, 04:01:33 pm

Title: Centering the game window.
Post by: underww on March 07, 2014, 04:01:33 pm
SFML basically centers the window when it is created.
but it doesn't consider Windows taskbar and also the game window's border size.
the border size is negligible but, the taskbar is a bit annoying.
here's some pictures for the explanation.

(http://i.imgur.com/eM6QpeY.png)

(http://i.imgur.com/TQwtvuV.png)

I want to set the window like the second image.
so, how can I get the taskbar's position, size and a window's border size?
any advice will be appreciated. thank you :)
Title: Re: Centering the game window.
Post by: Nexus on March 07, 2014, 04:07:57 pm
Have a look at the following functions:
sf::Window::setPosition()
sf::VideoMode::getDesktopMode()

You can't get the taskbar, menu or border size via SFML.
Title: Re: Centering the game window.
Post by: underww on March 07, 2014, 04:16:32 pm
unfortunately, they were not useful.
this is the same as the initial position.

sf::Window window(...);
auto desktop = sf::VideoMode::getDesktopMode();
window.setPosition(desktop.width/2 - window.getSize().x/2, desktop.height/2 - window.getSize().y/2);
Title: Re: Centering the game window.
Post by: Nexus on March 07, 2014, 04:41:01 pm
Yes, of course; after all you're setting the position to the center of the screen, and not to the center of the screen without taskbar.

You have to account for the latter manually (either by hardcoding a fixed value or calling WinAPI functions).
Title: Re: Centering the game window.
Post by: underww on March 07, 2014, 04:47:11 pm
ok, thanks for the replies. :)
i don't think everyone put the taskbar on the bottom.
so, i'd better to use some WinAPI functions.