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

Author Topic: Centering a bordered window in SFML  (Read 2838 times)

0 Members and 1 Guest are viewing this topic.

Sumzary

  • Guest
Centering a bordered window in SFML
« 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?
« Last Edit: December 16, 2013, 02:10:17 pm by Sumzary »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Centering a bordered window in SFML
« Reply #1 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sumzary

  • Guest
Re: Centering a bordered window in SFML
« Reply #2 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:


I want to fix this by moving the window left a bit in a neat manner.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Centering a bordered window in SFML
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sumzary

  • Guest
Re: Centering a bordered window in SFML
« Reply #4 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?
« Last Edit: December 16, 2013, 03:15:46 pm by Sumzary »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Centering a bordered window in SFML
« Reply #5 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... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sumzary

  • Guest
Re: Centering a bordered window in SFML
« Reply #6 on: December 16, 2013, 03:45:51 pm »
Well thanks anyway ;D
Merry christmas dude!

Sumzary

  • Guest
Re: Centering a bordered window in SFML
« Reply #7 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 ;)

 

anything