Jump to content
  • Advertisement

Archived

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

Brad8383

SDL Mouse problems

This topic is 5288 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

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!