SFML community forums

Help => Window => Topic started by: Mars_999 on June 04, 2012, 07:35:50 am

Title: sf::Window and windowed mode screensize
Post by: Mars_999 on June 04, 2012, 07:35:50 am
I see getSize() is only for the render screen size... but how can I find out what the size of the window is, is one is running a windowed app vs. fullscreen?

Thanks!
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 04, 2012, 08:01:02 am
You can't. Why would you need to know the total size of the window?
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 04, 2012, 08:13:09 am
I am trying to place the mouse cursor in the middle of the screen and in window mode this isn't centered when the user right clicks to go into a mouse move mode to rotate the view....
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 04, 2012, 08:52:06 am
Quote
I am trying to place the mouse cursor in the middle of the screen and in window mode this isn't centered when the user right clicks to go into a mouse move mode to rotate the view....
If you want to put the cursor in the middle of the screen (desktop), then you can:
- get the desktop size with sf::VideoMode::getDesktopMode()
- place the cursor relatively to the desktop with sf::Mouse::setPosition(p)

If you want to put the cursor in the middle of your window, then you can:
- get the window size with window.getSize()
- place the cursor relatively to the window with sf::Mouse::setPosition(p, window)
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 04, 2012, 11:48:12 am
Quote
I am trying to place the mouse cursor in the middle of the screen and in window mode this isn't centered when the user right clicks to go into a mouse move mode to rotate the view....
If you want to put the cursor in the middle of the screen (desktop), then you can:
- get the desktop size with sf::VideoMode::getDesktopMode()
- place the cursor relatively to the desktop with sf::Mouse::setPosition(p)

If you want to put the cursor in the middle of your window, then you can:
- get the window size with window.getSize()
- place the cursor relatively to the window with sf::Mouse::setPosition(p, window)

tried that no difference in window mode... still not in the center
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 04, 2012, 11:50:00 am
Sorry but can you be a little clearer, and give more details please?

You tried what, what was the result, and what did you expect?
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 04, 2012, 11:51:51 am
Sorry but can you be a little clearer, and give more details please?

You tried what, what was the result, and what did you expect?

I tried your code example and the cursor is off to the left in windowed mode.

Thanks!
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 04, 2012, 12:05:21 pm
Quote
I tried your code example
But which one? What do you want to do? Center cursor in the desktop, or in your window?

Ok wait... show us a complete and minimal code that reproduces your problem (shouldn't be bigger than 20 lines of code), it will be much faster :)
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 04, 2012, 12:07:40 pm
void NX::Camera::MouseMovement(int x, int y)
{
        NX::App* p = NX::App::Get();
        //float screenCenterX = static_cast<float>(p->GetWindow()->getSize().x) * .5f;
        //float screenCenterY = static_cast<float>(p->GetWindow()->getSize().y) * .5f;
        float screenCenterX = static_cast<float>(sf::VideoMode::getDesktopMode().width)  * .5f;
        float screenCenterY = static_cast<float>(sf::VideoMode::getDesktopMode().height) * .5f;
        float xf = static_cast<float>(x);
        float yf = static_cast<float>(y);
        if(prevX != xf || prevY != yf)
        {                      
                float deltaX = xf - screenCenterX;
                float deltaY = yf - screenCenterY;
                xRot += deltaY;
                yRot += deltaX;
                MaxCameraRotationX();
                //sf::Mouse::setPosition(sf::Vector2i(static_cast<int>(screenCenterX),
//                                                                                      static_cast<int>(screenCenterY)));
                sf::Mouse::setPosition(sf::Vector2i(static_cast<int>(screenCenterX),
                                                                                        static_cast<int>(screenCenterY)),
                                                                                        p->GetWindow());
                prevX = xf;
                prevY = yf;
        }
}
 

This is for a RenderWindow if that matters....

BTW this only happens when the windowed mode screen is not maximized...
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 04, 2012, 12:12:51 pm
You're not doing what I said, you're mixing both solutions. Please read my previous message carefully, and try to understand what you do ;)
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 05, 2012, 12:03:12 am
Not sure if you re-read my post update, but yes your solution works only if the windowed(window) is maximized not reduced to some other size....
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 05, 2012, 07:50:30 am
Fine. But your code is still incorrect. If you tried something else, show me what you did.
Title: Re: sf::Window and windowed mode screensize
Post by: Mars_999 on June 06, 2012, 12:18:11 am
Fine. But your code is still incorrect. If you tried something else, show me what you did.

How so?

I have tried your send the sf::Window to the set mousePos() and doesn't make a difference and I have tried the getDesktopMode() with/without every combo... So unless you have a test case to verify your solution works it doesn't work when I in window mode and NOT maximized....  Pretty simple test case IMO...

Thanks!

Update!
I see that the desktop mode returns what the OS is running at... I am looking at it still but there maybe something with a logic bug on my side... if I find it I will report back. Thanks
Title: Re: sf::Window and windowed mode screensize
Post by: Laurent on June 06, 2012, 08:21:02 am
It would already be solved if you did what I suggested previously ;)
Quote
show us a complete and minimal code that reproduces your problem (shouldn't be bigger than 20 lines of code)