SFML community forums

Help => Window => Topic started by: Darkpony on April 16, 2017, 01:46:17 am

Title: resizing a window by dragging it and using sf::view
Post by: Darkpony on April 16, 2017, 01:46:17 am
I am trying to have my map stretch when i either full screen it using the box or slowly drag the borders using sf view. I have tried various methods doing that however they all failed. The window resizes but the map stays the same size.  Here we have

 
case sf::Event::Resized:
        if (event.type == sf::Event::Resized)
        {
                sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                window.setView(sf::View(visibleArea));
                window.draw(map);
                /*sf::View view(sf::FloatRect(0, 0, 1000, 600));                               
                window.create(sf::VideoMode(event.size.width, event.size.height, 32),"Tilemap");
                view.setSize(event.size.width, event.size.height);
                window.setView(view);
                window.draw(map);*/

                std::cout << "Resized" << std::endl;
        }
        break;
Title: Re: resizing a window by dragging it and using sf::view
Post by: Hapax on April 16, 2017, 02:12:03 am
If you want the "scene" to stretch to fit the window, keep the same view. That is, there's no need to update the view on window resize.

If you want a map that stretches but a UI (for example) that doesn't, use two separate views: one that stays the same for the map (so it stretches) and another for the UI that gets updated when the window is resized (so that it doesn't stretch).
Title: Re: resizing a window by dragging it and using sf::view
Post by: Darkpony on April 16, 2017, 05:25:15 am
Well I wanted to resize the window and view because i have an event that moves sprites. Once the window is stretched i lose my pixels. I figured view had a function for this, however I figure I might be able to divide by the window size.x.y making the aspect ratio always similar. I did something like this in glut and ill probably try it here.
Title: Re: resizing a window by dragging it and using sf::view
Post by: Hapax on April 17, 2017, 01:21:09 am
Looks like you want to convert between world/view co-ordinates and pixel positions.
The window has functions for this (they use a view - either the current one or the specified one).
See this part of the view tutorial:
https://www.sfml-dev.org/tutorials/2.4/graphics-view.php#coordinates-conversions

Although, it's advisable to read that tutorial in its entirety.