#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window ( sf::VideoMode ( 1212, 800 ), "View resize test" );
sf::View view ( sf::Vector2f ( 606, 400 ), sf::Vector2f ( 1212, 800 ) );
window.setView ( view );
sf::Texture tex;
tex.loadFromFile ( "image.png", sf::IntRect ( 92, 343, 1138, 168 ) );
sf::Sprite sprite;
sprite.setTexture ( tex );
while ( window.isOpen() ) {
sf::Event event;
while ( window.pollEvent ( event ) ) {
if ( event.type == sf::Event::Closed ) {
window.close();
} else if ( event.type == sf::Event::Resized ) {
view.setCenter ( event.size.width / 2, event.size.height / 2 );
view.setSize ( event.size.width, event.size.height );
window.setView(view);
std::cout << "New size is: width = " << event.size.width << " height = " << event.size.height << std::endl;
}
}
window.clear();
window.draw ( sprite );
window.display();
}
}