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

Author Topic: sf::Window and windowed mode screensize  (Read 3821 times)

0 Members and 1 Guest are viewing this topic.

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
sf::Window and windowed mode screensize
« 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #1 on: June 04, 2012, 08:01:02 am »
You can't. Why would you need to know the total size of the window?
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #2 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....

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #3 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)
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #4 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #5 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?
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #6 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #7 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 :)
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #8 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...
« Last Edit: June 04, 2012, 12:13:03 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #9 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 ;)
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #10 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....

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #11 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.
Laurent Gomila - SFML developer

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: sf::Window and windowed mode screensize
« Reply #12 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
« Last Edit: June 06, 2012, 02:37:55 am by Mars_999 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Window and windowed mode screensize
« Reply #13 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)
Laurent Gomila - SFML developer

 

anything