hello
I'm having trouble understanding this Views and Viewport situation:
in this code, the text appears while the mouse cursor is inside view_one, which occupies 100% of the height and 80% of the width (because the Viewport is (0, 0, 0,8, 1)):
#include <SFML/Graphics.hpp>
int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Views");
sf::View view_one, view_two;
view_one.setViewport(sf::FloatRect(0, 0, 0.8, 1));
view_two.setViewport(sf::FloatRect(0.8, 0, 0.2, 1));
sf::Font font;
font.loadFromFile("LondrinaSolid-Regular.otf");
sf::Text text("Cursor is inside View One", font);
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event)){
if(event.type == sf::Event::Closed) window.close();
}
sf::Vector2f pos_in_view = window.mapPixelToCoords(sf::Mouse::getPosition(window), view_one);
window.clear();
if (sf::IntRect(view_one.getCenter().x-view_one.getSize().x/2, view_one.getCenter().y-view_one.getSize().y/2, view_one.getCenter().x+view_one.getSize().x/2, view_one.getCenter().y+view_one.getSize().y/2).contains(sf::Vector2i(pos_in_view))){
window.setView(view_one);
window.draw(text);
}
window.display();
}
return 0;
}
it works. but if I resize the view_one,
view_one.setSize(3000, 3000);
the viewport seems to be resized too
is that supposed to happen? how do I keep the correct proportions, so I can always check if the cursor is inside a given sf::View?
EDIT: I know that the VIEW should be resized, and with it the text inside. but the Viewport should not, I think. notice how the viewport shrinks to almost half the window size in the second image
EDIT 2: it works if I use
view_one.reset(sf::FloatRect(0, 0, 3000, 3000));
is this a bug? I checked the source, and apart from resizing the view (like setSize() does), reset() just recalculates the view center and set the rotation to 0;