Sign in to follow this  
subflood

SDL mouse

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

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