Sign in to follow this  

SDL mouse

This topic is 4584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, how can I make sure the mouse cursor stays in the SDL window? I used to use Allegro and the library provided functions to limit where the mouse cursor can be, is there something similar in SDL?

Share this post


Link to post
Share on other sites
Well that doesn't really work because the mouse cursor can still be outside the SDL window except now the user just doesn't see the mouse cursor. What I need is a function that will only let the mouse be between two numbers such as (0, 800). Similar to when you're on windows and you move the mouse all the way to the left edge of your desktop/monitor the mouse won't go any further.

Share this post


Link to post
Share on other sites
Quote:
Original post by subflood
Well that doesn't really work because the mouse cursor can still be outside the SDL window except now the user just doesn't see the mouse cursor. What I need is a function that will only let the mouse be between two numbers such as (0, 800). Similar to when you're on windows and you move the mouse all the way to the left edge of your desktop/monitor the mouse won't go any further.


Well, here is a ghetto oldschool solution.

//*******************************
//calculate mouse movements
POINT pMouse;
GetCursorPos(&pMouse);

if (pMouse.x < winPosX) { SetCursorPos(winPosX,pMouse.y);}
if (pMouse.x > winPosX+winWidth) { SetCursorPos(winPosX+winWidth,pMouse.y);}
if (pMouse.y < winPosY) { SetCursorPos(pMouse.x,winPosY);}
if (pMouse.y > winPosY+winHeight) { SetCursorPos(pMouse.x,winPosY+winHeight);}

...you might also want to check if the window handle has focus otherwise you'll have a limited cursor when you alt-tab out of you application as well.


marty78

Share this post


Link to post
Share on other sites

This topic is 4584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this