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

Author Topic: Fixed viewport possible?  (Read 2249 times)

0 Members and 1 Guest are viewing this topic.

eggw

  • Newbie
  • *
  • Posts: 9
    • View Profile
Fixed viewport possible?
« on: June 06, 2016, 08:53:02 pm »
I have a view used to draw the black bar at the bottom. I want that black bar to have a fixed size, and to always be in the bottom-center of the window. By default, the window size is as such, and everything is fine:



What I WANT to happen when I increase the size of the screen is have the black bar remain the same size:



But instead, the black bar scales to the new window size (due to SFML viewports being defined as a ratio of the screen) and this happens:



Is there a solution for this, or is it impossible due to the way SFML's viewports work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Fixed viewport possible?
« Reply #1 on: June 06, 2016, 09:14:07 pm »
This is a non-problem. You can very easily switch from ratio to fixed size by multiplying / dividing by the window size whenever it changes.

const sf::Vector2f barSize(... fixed size...);

on resize event
{
    viewport.width = barSize.x / window.width;
    viewport.height = barSize.y / window.height;
    viewport.left = (1 - viewport.width) / 2;
    viewport.top = 1 - viewport.height;
}

(disclaimer: untested inaccurate pseudo-code)
Laurent Gomila - SFML developer

eggw

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Fixed viewport possible?
« Reply #2 on: June 08, 2016, 03:17:01 am »
Thanks Laurent, it worked like a charm.