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

Author Topic: resizing a window by dragging it and using sf::view  (Read 2384 times)

0 Members and 1 Guest are viewing this topic.

Darkpony

  • Newbie
  • *
  • Posts: 7
    • View Profile
resizing a window by dragging it and using sf::view
« 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;
« Last Edit: April 16, 2017, 01:51:11 am by Darkpony »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: resizing a window by dragging it and using sf::view
« Reply #1 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).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Darkpony

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: resizing a window by dragging it and using sf::view
« Reply #2 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.
« Last Edit: April 16, 2017, 05:32:27 am by Darkpony »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: resizing a window by dragging it and using sf::view
« Reply #3 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything