I have this single code...
#include <SFML/Graphics.hpp>
#define windowWidth 600
#define windowHeight 300
int main()
{
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Views");
sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
view.zoom(2);
window.setView(view);
sf::RectangleShape back (sf::Vector2f(windowWidth, windowHeight));
back.setFillColor(sf::Color::White);
sf::RectangleShape rect (sf::Vector2f(200, 100));
rect.setFillColor(sf::Color::Red);
rect.setPosition(windowWidth - rect.getSize().x, windowHeight - rect.getSize().y); // position in the lower right corner
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(back);
window.draw(rect);
window.display();
}
return 0;
}
...which might position the red rectangle in the lower right corner of the window.
However, when I zoom the view in (as in the code), it obviously moves along with the entire window.
I have some doubts:
- To correct the positioning of the red rectangle and place it in the lower right corner of the global window, I currently have to do some calculations considering the zoom factor, original rectangle size, etc. Is there any easier way to position this rectangle in the lower-right corner of the global window?
- How do I prevent some objects from being resized by the zoom of the view?
- What do I have to do to have multiple active views in the same window?