Archived

This topic is now archived and is closed to further replies.

Brad8383

SDL Mouse problems

Recommended Posts

Im having problems with getting the mouse button that was pressed. Determining whether the left mouse button works for me and here is the code I used:
for(;; )
	{
		if(SDL_PollEvent(&event)==0)
		{
		}
		else
		{
			if(event.type == SDL_QUIT)
				break;
			if(event.type == SDL_MOUSEBUTTONDOWN)
			{
				SDL_PumpEvents();
				Uint8 button = SDL_GetMouseState(NULL,NULL);
				if(button & SDL_BUTTON_LEFT)
				{
					break;
				}
			}
		}
	} 
however if I changed SDL_BUTTON_LEFT to RIGHT it does not work. Instead of the if statement executing when the right button is down it still executes if and only if the left mouse button is down. [edited by - Brad8383 on April 2, 2004 8:57:17 PM]

Share this post


Link to post
Share on other sites
You''re missing out on some aspects of the SDL_Event structure.

// loop through the event queue

SDL_Event event;
while (SDL_PollEvent(&event))
{
// what type of event?

switch (event.type)
{
case SDL_MOUSEBUTTONUP:
{
BitStream* data = new BitStream;
if (!data)
LogSystem->LogItem("Could not create message data! Out of memory!", __FILE__, __LINE__, TYPE_WARNING_ENGINE);

data->Write(BUTTON_UP);
data->Write(event.button.x);
data->Write(event.button.y);
data->Write(event.button.button);

MessageManager->DispatchMessage(data, GLOBAL_MSG, KERNEL_MSG, MOUSE_MSG);

} break;

} // end switch


} // end while


event.button.button contains the value you need to determine whether the button was SDL_BUTTON_LEFT or SDL_BUTTON_RIGHT (or any other type of SDL_BUTTON)

_________________________________________________________________

Drew Sikora
President, Lead Programmer - Blade Edge Software
Staff Writer, Newsletter Editor - GameDev.net
Community Relations - Game Institute

Share this post


Link to post
Share on other sites