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

Author Topic: Forcing RenderWindow position (linux-ubuntu)  (Read 1328 times)

0 Members and 1 Guest are viewing this topic.

Luislve17

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Forcing RenderWindow position (linux-ubuntu)
« on: December 21, 2017, 03:48:36 pm »
Hello
I was trying to move my window to achieve something like this:


But the call to setPosition() for my window cant go any further beyond the limit over the ubuntu launcher bar.

I was wandering if there is a way to force its position down there

Im just doing this:
window->setPosition(sf::Vector2i( 0 , 690 /*sf::VideoMode::getDesktopMode().height*/));
 
The position has to be a function of the desktop resolution but I commented to try to do it manually
« Last Edit: December 21, 2017, 03:54:34 pm by Luislve17 »

Luislve17

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Forcing RenderWindow position (linux-ubuntu)
« Reply #1 on: December 21, 2017, 07:46:57 pm »
Okay, I think I got a way around the issue.
First of all, I needed to make my window borderless (for my project, nothing to do with yours) but this helped me to position the window with extra accuracy (idk why but with borders I got weird and non-accurate positions)

Next, I had to make the window big enough to move it where I wanted in order to have a portion of the window in and the other one out:

        // Going full savage with this starting video mode:
        sf::VideoMode vm(sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height);
        sf::RenderWindow* window = new sf::RenderWindow(vm, "Effects", sf::Style::None);
        window->setFramerateLimit(60);
        ...
 

Then, I had to move the window to the bottom (now that i can, cuz magic) and resize it.

        sf::VideoMode vm(sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height);
        sf::RenderWindow* window = new sf::RenderWindow(vm, "Effects", sf::Style::None);
        window->setFramerateLimit(60);
        // Here, I move it to where i want and resizing to the needed dimensions
        window->setPosition(sf::Vector2i( 0, sf::VideoMode::getDesktopMode().height - 54)); // 54 its just my  ubuntu navbar height
        window->setSize(sf::Vector2u(window->getSize().x, 54));
 

The problem after this is that my square gets all shrinked, this may or may not be because of the resizing event that triggers the call of "setSize()" on my window.


(The white part is just empty space)

So I added a event handler to my event handling function

if (e.type == sf::Event::Resized){
            w->setView(sf::View(sf::FloatRect(0.f, 0.f,
                                                static_cast<float>(w->getSize().x),
                                                static_cast<float>(w->getSize().y))
                                                        )
                                                );
                }
 

And thats it



Hope I helped somebody. If not feel free to delete this post
Happy Holydays :)


 

anything