Mouse button/movement troubles

To handle mouse input in my game I have this code inside my event
handler:

case SDL_MOUSEMOTION:
	if(!ignore) {
		mov_mouse_x += event.motion.xrel;
		mov_mouse_y += event.motion.yrel;
		mov_mouse_z = 0;
		SDL_WarpMouse(thegame->options.GetWidth()/2,

thegame->options.GetWidth()/2);
ignore = true;
}
else ignore = false;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT)
buttons[0] = true;
else buttons[1] = true;
break;
case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT)
buttons[0] = false;
else buttons[1] = false;
break;

The problem is that when the mouse is moving, and I press a button, it
starts flickering, like the button is being pressed on and off. The
code works as expected if the mouse wasn’t moving while button was
pressed. Any ideas?

Thanks,
Andrew

From going through the code,
SDL_WarpMouse resets the mouse states

Makes sense for most applications to have this as the default (lets say, you
move off of one button onto another); yet there isn’t an option to get it to
either retain button state, or give it new ones.

Could you use the ignore (which i’m presuming you’re using to stop the warpmouse
event changing your mouse position again) to prevent the SDL_MOUSEBUTTONs
getting triggered ?

Regards,
John

Andrew wrote:> To handle mouse input in my game I have this code inside my event

handler:

case SDL_MOUSEMOTION:
if(!ignore) {
mov_mouse_x += event.motion.xrel;
mov_mouse_y += event.motion.yrel;
mov_mouse_z = 0;
SDL_WarpMouse(thegame->options.GetWidth()/2,
thegame->options.GetWidth()/2);
ignore = true;
}
else ignore = false;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT)
buttons[0] = true;
else buttons[1] = true;
break;
case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT)
buttons[0] = false;
else buttons[1] = false;
break;

The problem is that when the mouse is moving, and I press a button, it
starts flickering, like the button is being pressed on and off. The
code works as expected if the mouse wasn’t moving while button was
pressed. Any ideas?

Thanks,
Andrew


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

At 11:18 AM 16/10/2003 +0100, you wrote:

From going through the code,
SDL_WarpMouse resets the mouse states

Makes sense for most applications to have this as the default (lets say,
you move off of one button onto another); yet there isn’t an option to get
it to either retain button state, or give it new ones.

Could you use the ignore (which i’m presuming you’re using to stop the
warpmouse event changing your mouse position again) to prevent the
SDL_MOUSEBUTTONs getting triggered ?

So do you mean that the SDL_WarpMouse function is also triggering
MOUSEBUTTONUP events? The code looks like standard code for using the
mouse in FPSes and other games so it’d be handy to know how to make it work
right :wink: (Im not the original poster)

Neil.

I’ve simplified my code to:

SDL_PumpEvents();
int movement_x, movement_y;
Uint8 state = SDL_GetRelativeMouseState(&movement_x,

&movement_y);

mov_mouse_x += movement_x;
mov_mouse_y += movement_y;
mov_mouse_z = 0;

if(state & SDL_BUTTON(SDL_BUTTON_LEFT)) buttons[0] = true;
else buttons[0] = false;
if(state & SDL_BUTTON(SDL_BUTTON_RIGHT)) buttons[1] = true;
else buttons[1] = false;

The button handling works perfectly when the mouse is not moving, but
still, if I click the mouse while the mouse is still moving, it never
finds out that the button has been released.

Has anyone come across this before?

-Andrew

I originally was having the trouble under Windows. I then rebooted into
Linux, tested identical code there, and it worked fine. I realized it’s
probably not my code then. So I went back into Windows, downloaded an
updated version of SDL, and the problem was fixed.

Sorry if I troubled anyone, over such a silly thing.

  • Andrew