SDL mouse

Started by
2 comments, last by marty78 18 years, 11 months ago
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?
Advertisement
Yes, SDL_WM_GrabInput. Ex: SDL_WM_GrabInput( SDL_GRAB_ON );
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.
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

This topic is closed to new replies.

Advertisement