SDL Mouse States
Posted: Wed Sep 01, 2010 9:55 am
All I need is a boolean that is true if the left mouse button is down and false if the left mouse button is up.
I can't find it.
Please Help!
I can't find it.
Please Help!
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
Code: Select all
bool lmbPressed = false; // lmb == left mouse button
if( g_Event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT ) {
lmbPressed = true;
}
if( g_Event.type == SDL_MOUSEBUTTONUP ) {
lmbPressed = false;
}
Code: Select all
struct Mouse
{
int dx, dy;
int oldX, oldY;
unsigned int buttons;
unsigned int oldButtons;
};
Code: Select all
SDL_PumpEvents();
mouse.oldButtons = mouse.buttons;
mouse.oldX = mouse.dx;
mouse.oldY = mouse.dy;
mouse.buttons = SDL_GetMouseState(&mouse.dx, &mouse.dy);
Code: Select all
bool mouseDown(int button)
{
return currMouse(button) && (!oldMouse(button));
}
bool mouseStillDown(int button)
{
return currMouse(button) && (oldMouse(button));
}
Code: Select all
#define currMouse(x) ((mouse.buttons&SDL_BUTTON(x)) != 0)
#define oldMouse(x) ((mouse.oldButtons&SDL_BUTTON(x)) != 0)