SFML community forums

Help => Window => Topic started by: Luislve17 on December 21, 2017, 03:48:36 pm

Title: Forcing RenderWindow position (linux-ubuntu)
Post by: Luislve17 on December 21, 2017, 03:48:36 pm
Hello
I was trying to move my window to achieve something like this:
(https://cdn.pbrd.co/images/GZfqmMu.png)

But the call to setPosition() for my window cant go any further beyond the limit over the ubuntu launcher bar.
(https://cdn.pbrd.co/images/GZfqJOr.png)
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
Title: Re: Forcing RenderWindow position (linux-ubuntu)
Post by: Luislve17 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.

(https://cdn.pbrd.co/images/GZgYJ7M.png)
(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

(https://cdn.pbrd.co/images/GZgZpKh.png)

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