Reputation: 8277
I have a simple test script, which it meant to change a boolean when the user clicks within the dimensions of the button but it is not working.
I approached it like so:
while( SDL_PollEvent( &event ) ) {
switch( event.type ){
case SDL_QUIT: quit = true; break;
case SDL_MOUSEMOTION: mouseX = event.motion.x; mouseY = event.motion.y; break;
case SDL_MOUSEBUTTONDOWN: click = true;
}
}
Button btn_settings(btn_x,btn_y);
if(btn_settings.IsIn(mouseX,mouseY)){
btn_settings.RenderImg(menu,screen,"button_on.png","Settings");
if(click){
quit = true;
}
} else {
btn_settings.RenderImg(menu,screen,"button.png","Settings");
}
The problem is if i click any where then click equals true, then if the mouse is over
the quit button it exits even if the button wasn't pressed when over the button.
I'm confused how i can make it work properly.
Upvotes: 0
Views: 87
Reputation: 16207
Try handling your "click" event on mouse button up instead. I've never used SDL but I suspect there is a SDL_MOUSEBUTTONUP
defined. Otherwise you don't know if they want to perform a drag operation or if they moved the mouse someplace else before letting go of the mouse button.
Upvotes: 1