SFML community forums

Help => General => Topic started by: jjjaime on April 01, 2013, 02:55:30 pm

Title: Shape deformed after resizing the window
Post by: jjjaime on April 01, 2013, 02:55:30 pm
I've created a very simple app that renders a square with size 200:

sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(200, 200));
rectangle.setFillColor(sf::Color::Magenta);
rectangle.setPosition(10, 10);
window.draw(rectangle);
 

The square is rendered correctly. However, when the window is resized, the square is deformed into a rectangle and the size is reduced or increased according to the size of the window. Perhaps it's my misunderstanding and size and position are related to the window size? Is that correct? How could I create a shape with a specific size (and the same in height and width)?

I'm using the SFML v2.0 available at http://www.sfml-dev.org/download.php (not the latest version in Git).
Title: Re: Shape deformed after resizing the window
Post by: Nexus on April 01, 2013, 03:14:27 pm
You have to catch the Resized event and resize the window's view accordingly.
Title: Re: Shape deformed after resizing the window
Post by: jjjaime on April 01, 2013, 05:14:09 pm
Thanks. It works. I've used the following code:

if (event.type == sf::Event::Resized) {
      window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
}
 

I will look into the View class. However, I cannot understand why it is required. I guess that the normal situation should be that the whole window corresponds to a view unless it is modified by the developer.