SFML community forums

Help => Window => Topic started by: Sumzary on December 16, 2013, 02:05:15 pm

Title: Centering a bordered window in SFML
Post by: Sumzary on December 16, 2013, 02:05:15 pm
I want to make it so when a sf::Window gets created, if it has a border, the position is set a bit to the left, to compensate for the border. Currently I just do this:

window.create(sf::VideoMode(conf::res.x, conf::res.y, conf::bpp), "Vania", sf::Style::Resize | sf::Style::Close, settings);
window.setPosition(window.getPosition() - sf::Vector2i(4, 0));

But there is a flicker when the position is updated and I'm not sure it is fully cross-platform (with different styles and whatnot). So I thought about changing the window implementation code (WindowImplWin32.cpp etc) and do it that way, but im not not sure how to get the border width in those :[

What would be the most clean way to do this?
Title: Re: Centering a bordered window in SFML
Post by: eXpl0it3r on December 16, 2013, 02:29:16 pm
SFML doesn't have a such functionality - it's not a window manager - and simply assuming the border width is 4px it's "cross-platform" at all. Why does have to be completely centered?
Title: Re: Centering a bordered window in SFML
Post by: Sumzary on December 16, 2013, 02:46:01 pm
I know SFML doesn't have such functionality.
Assuming is what I have been doing so far and not at all what I am asking.


Currently, if i create a bordered window witht the same width as the screen i get part of the window cut off:
(http://www.foopics.com/showfull/ebc71c31265f9330192bb443c37c3d94)

I want to fix this by moving the window left a bit in a neat manner.
Title: Re: Centering a bordered window in SFML
Post by: eXpl0it3r on December 16, 2013, 02:56:15 pm
Every window manager and every style you can apply to windows can usually choose whatever width they want. The only thing you could do, is to create a border-less window from the beginning and if wanted add your own titlebar with buttons.
Title: Re: Centering a bordered window in SFML
Post by: Sumzary on December 16, 2013, 03:09:13 pm
Really what I want to do, is change the code in WindowImplWin32.cpp, WindowImplX11.cpp etc.
Get the window border width, and move the window left by it during creation, then recompile SFML.

How should I get the border width?
Title: Re: Centering a bordered window in SFML
Post by: eXpl0it3r on December 16, 2013, 03:24:10 pm
Well then you're mostly on your own. Dig through the Win32 and X API to find the needed functions. I kind of doubt that anyone will know that from top of their head, given there is even such a function... ;)
Title: Re: Centering a bordered window in SFML
Post by: Sumzary on December 16, 2013, 03:45:51 pm
Well thanks anyway ;D
Merry christmas dude!
Title: Re: Centering a bordered window in SFML
Post by: Sumzary on December 16, 2013, 03:56:58 pm
Putting this here, maybe it will help someone in the future. Simple really, sorry to have started a whole thread about it.

Had to change this line:
int left   = (GetDeviceCaps(screenDC, HORZRES) - static_cast<int>(mode.width))  / 2;
to this:
int left   = (GetDeviceCaps(screenDC, HORZRES) - static_cast<int>(mode.width))  / 2 - GetSystemMetrics(SM_CXSIZEFRAME);

Now to figure out what I need to change for it to be cross platform ;)