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

Author Topic: Is possible to force mouse to stay in sf::RenderWindow?  (Read 1703 times)

0 Members and 1 Guest are viewing this topic.

XeRaCKeR

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Is possible to force mouse to stay in sf::RenderWindow?
« on: January 18, 2014, 12:48:28 am »
Hi, I am learning OpenGL under SFML, and I am trying to move the 3D camera with mouse.

Is there any way to force the cursor to stay in the window? Since I can almost force it with the next code, but it doesnt work when you move the mouse so fast than the cursor can leave the window.

            case sf::Event::MouseMoved:
                // For camera rotation
                gradh += (event.mouseMove.x - (int)window.getSize().x/2)/7;
                grady += (event.mouseMove.y - (int)window.getSize().y/2)/7;
                // Force mouse to stay in the middle
                sf::Mouse::setPosition(sf::Vector2i(window.getSize().x/2,window.getSize().y/2),window);
                break;

Or another way to rotate the camera with mouse?

Sorry if bad english. Greetings

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Is possible to force mouse to stay in sf::RenderWindow?
« Reply #1 on: January 18, 2014, 02:27:57 am »
Maybe you could also react to the MouseLeave event.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor