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

Author Topic: How do I get the dimensions of a window?  (Read 2434 times)

0 Members and 2 Guests are viewing this topic.

fallout

  • Newbie
  • *
  • Posts: 15
    • View Profile
How do I get the dimensions of a window?
« 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.

eXpl0it3r

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

fallout

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How do I get the dimensions of a window?
« Reply #2 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.

eXpl0it3r

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

fallout

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How do I get the dimensions of a window?
« Reply #4 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.
« Last Edit: September 25, 2012, 09:27:03 am by fallout »

 

anything