SFML community forums
Help => Window => Topic started by: nefx on June 17, 2011, 08:22:46 am
-
Here is the code from tutorial modified to handle window event resized.
////////////////////////////////////////////////////////////
// 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!
-
Why are you trying to resize the window to its new size?
-
Thought I need to handle the event but it seems window is resized automatically. Stupid me.
-
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:
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...
-
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 (https://github.com/SFML/SFML/blob/master/examples/window/Window.cpp))
-
ok, works now:
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.