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

Author Topic: Views vs window confusion  (Read 2210 times)

0 Members and 1 Guest are viewing this topic.

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
Views vs window confusion
« on: April 24, 2018, 09:41:52 pm »
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?
« Last Edit: April 24, 2018, 11:01:15 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: Views vs window confusion
« Reply #1 on: April 24, 2018, 11:02:24 pm »
So what's your final goal?

Did you read and understand the view tutorial?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rogeriodec

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Views vs window confusion
« Reply #2 on: April 25, 2018, 08:51:56 pm »
Yes, I read. But since I'm a beginner in sfml, I still have not got the whole logic of the thing. And not always this tutorial is so understandable for beginners.
I've also watched several tutorial videos on youtube that are expanding my understanding of sfml.
But sometimes a simple, but less laconic answer can help.
In any case, I had the opportunity to have this support in StackOverflow and now I know how to solve it.  8)
« Last Edit: April 25, 2018, 08:55:15 pm by rogeriodec »