SFML community forums

Help => Window => Topic started by: fallout on September 23, 2012, 09:56:54 am

Title: How do I get the dimensions of a window?
Post by: fallout on September 23, 2012, 09:56:54 am
[Using SFML 2.0]
If a function has no access to the current RenderWindow, is it possible to get a handle of the RenderWindow? If not, I'm assuming I must pass a reference to RenderWindow in.

I'm basically trying to create a rectangle shape, initialized in a constructor that is equal to the width of a window and half its height, but I just realized I have no reference to the window, unless I pass it in.
Title: Re: How do I get the dimensions of a window?
Post by: eXpl0it3r on September 23, 2012, 01:06:32 pm
Well if the function has no reference/handle to the window, how should it get information from it?
Global objects should not be used and calling OS specific APIs shouldn't be done either.
Easiest part is to either pass in the dimension of the window (e.g. sf::Vector2i) or pass the whole window as reference (e.g. foo(const sf::RenderWindow& wnd)).
If you only need the size then you should only pass the size, if you need more than you can pass a reference  to the whole window.
Title: Re: How do I get the dimensions of a window?
Post by: fallout on September 24, 2012, 06:27:47 am
Thanks. I was thinking SFML had something similar to SDL_GetVideoSurface() but it doesn't so I just passed as a parameter.
Title: Re: How do I get the dimensions of a window?
Post by: eXpl0it3r on September 24, 2012, 08:33:33 am
Unlike SDL SFML uses a object oriented approach with C++ and avoids as much as possible global functions.  )
Title: Re: How do I get the dimensions of a window?
Post by: fallout on September 25, 2012, 09:23:47 am
It's not a global function, but sorta is I suppose. Seems to give access to pointer to a static variable.

I suppose it wouldn't make sense though to have a method like that in SFML since SFML is capable of multiple windows, whereas SDL can only have a single window.