Patrick’s development blog

Getting mouse state in SDL

Posted in SDL / OpenGL by Patrick on June 23, 2009

I’ve decided to finally start a programming project after a very long break. I found the need to use mouse states when creating a Level editor for my RPG because regular events doesn’t really do what I want.

I want to add tiles fast and be able to hold the mouse key down, instead of clicking every time I want to add a tile.

Mouse states

int cx,cy;
Uint8 ms = SDL_GetMouseState(&cx, &cy);
if (ms & SDL_BUTTON(SDL_BUTTON_LEFT)) {
// the left mouse key is pressed
} else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
// the right mouse key is pressed
}