[SDL] mouse event handling

Peter Mulholland darkmatter at freeuk.com
Tue Sep 5 14:32:55 PDT 2006


Hello Bill,

Tuesday, September 5, 2006, 6:06:15 PM, you wrote:

> On Sun, Sep 03, 2006 at 05:51:03PM -0700, jonathan racioppo wrote:
>> Hi, 
>>    
>>   I have a simple question about SDL_MOUSEBUTTONDOWN (UP).  I couldnt find anything on how you can use that command on an image such as a button.  Lets say I made an update button and placed it in the middle of the screen using the command apply_surface (280, 350, update, screen);.  How would I make it so when someone clicks there it does something like update a bunch files from a specific location?  Thx in advance.
>>    

> if (event.type == SDL_MOUSEBUTTONDOWN)
> {
>   if (event.button.x >= 280 && event.button.x < 280 + ButtonImage->w &&
>       event.button.y >= 350 && event.button.y < 350 + ButtonImage->h)
>   {
>     update_a_bunch_of_files_from_a_specific_location();
>     /* You're weclome ;^) */
>   }
> }

Simple and effective :)

The only thing I would suggest is that you look for a mouse button up,
with the cursor in the same region THEN do the processing.


-- 
Best regards,
 Peter                            mailto:darkmatter at freeuk.com





More information about the SDL mailing list