Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Centering the game window.  (Read 3567 times)

0 Members and 1 Guest are viewing this topic.

underww

  • Newbie
  • *
  • Posts: 34
    • View Profile
Centering the game window.
« 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.





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 :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6274
  • Thor Developer
    • View Profile
    • Bromeon
Re: Centering the game window.
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

underww

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Centering the game window.
« Reply #2 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);
« Last Edit: March 07, 2014, 04:23:57 pm by underww »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6274
  • Thor Developer
    • View Profile
    • Bromeon
Re: Centering the game window.
« Reply #3 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

underww

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Centering the game window.
« Reply #4 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.

 

anything