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

Author Topic: [SFML2] Event Resized  (Read 8457 times)

0 Members and 1 Guest are viewing this topic.

nefx

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SFML2] Event Resized
« on: June 17, 2011, 08:22:46 am »
Here is the code from tutorial modified to handle window event resized.
Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events");

    // Start main loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Resize window : set new size
            if (Event.Type == sf::Event::Resized)
                App.SetSize(Event.Size.Width, Event.Size.Height);
        }

        // Display window on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Closing the window works fine however if I try to resize it keeps jumping between new and old size - looping in event loop. I don't know if it is my fault or a bug, any help appreciated!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] Event Resized
« Reply #1 on: June 17, 2011, 08:28:10 am »
Why are you trying to resize the window to its new size?
Laurent Gomila - SFML developer

nefx

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SFML2] Event Resized
« Reply #2 on: June 17, 2011, 11:00:24 am »
Thought I need to handle the event but it seems window is resized automatically. Stupid me.

Mugros

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SFML2] Event Resized
« Reply #3 on: June 25, 2011, 04:46:04 pm »
I am having the same problem. The thing is, that without handling the Resized event, the window resizes fine but the rendering area is stretched.
So if i start with a 800x600 window and i make it bigger everything i draw is still mapped to a 800x600 area and stretched to the new window size.
I used the tutorial and work my way up. Right now i just draw a sprite at the mouse coordinates, like a pointer. After i resize the window the position of the sprite doesn't match anymore.
I looked on the website and found:
Code: [Select]
void SetSize (unsigned int Width, unsigned int Height)
  Change the size of the rendering region of the window.

And i thought that i have to adjust the rendering area to the new size. But like the OP said, this results in strange behaviour.

I guess i have to change the view, but couldn't make it work yet...

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[SFML2] Event Resized
« Reply #4 on: June 25, 2011, 05:00:42 pm »
Quote from: "Mugros"
I guess i have to change the view, but couldn't make it work yet...
Yes, that's it. Use sf::RenderWindow::SetView if you're using a sf:RenderWindow. Or use 'glViewport(0, 0, event.Size.Width, event.Size.Height);' if you're using a sf::Window (look at this example)
SFML / OS X developer

Mugros

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SFML2] Event Resized
« Reply #5 on: June 25, 2011, 05:02:53 pm »
ok, works now:
Code: [Select]
case sf::Event::Resized:
App.SetView(sf::View(sf::FloatRect(0, 0, Event.Size.Width,Event.Size.Height)));
break;

My C++ is a bit rusty and i forgot the breaks  8)
Gave a funny effect.

I guess SetSize should be used when changing the resolution with a game menu.