You can also make a function that checks whether or not the pointer is within a given rect when the mouse button is clicked.
I wrote a set of functions to do that, utilising banks. Here's a better version by somebody else, based on my original code.