Mouse Click Region

Hi guys, I'm trying to create a UI which has a lot of buttons e.g. a keyboard. Is there a clever way of creating mouse click regions without a tonne of if loops?

I'm going to be using openGL to create the visual aspect and then track the mouse movement within the confines of my openGL interface.

I'm not too sure how much it will slow down the program if I do indeed use a tonne of if loops e.g.

1
2
3
4
5
if(mousePointer(x+12, x+20, y+15, y+50))
{
    //then the button we are clicking is "A"
    //hence do something
}


a.) I don't want to even think about trying to manually enter all the coordinates of the buttons.

b.) This method will also require me to add additional functions which will keep track of all these coordinates when resizing is concerned and this is just going to be a massive pain the behind.

Any suggestions guys?

c.) Performance is important so I want as little slow down as humanly possible.
Last edited on
You could have a rectangle and check if the click is inside the rectangle. This probably belongs to a button class.

If you want you could put all the rectangles (or buttons) in a container so you can easily loop through them all.
Thank you, very helpful, I'm looking into containers, looks promising.
Topic archived. No new replies allowed.