Say I have multiple button objects and I'm checking each on mouse move to see if any are highlighted (For picking / rollover purposes). Is it considered better practice to do the checking in the loop, or to have a method in the button object itself invoked for each button that does the checking? Here's my button object, set up currently to have each button check it's own bounding box - I've commented out the bit where it was checking in the loop by accessing the member variables of each button indirectly.
while( ThisButton ) {
//if((MouseX >= ThisButton->X && MouseX <= (ThisButton->X + ThisButton->Width)) && (MouseY >= ThisButton->Y && MouseY <= (ThisButton->Y + ThisButton->Height))) {
if( ThisButton->IsHighlighted( MouseX, MouseY ) ) {
OButton::HighlightedButton = ThisButton;
ThisButton = NULL;
break;
} else if( OButton::HighlightedButton == ThisButton ) {
OButton::HighlightedButton = NULL;
}
ThisButton = ThisButton->NextButton;
}
And here's the method for checking if the button is highlighted:
bool OButton::IsHighlighted( int MouseX, int MouseY ) {
return((MouseX >= X && MouseX <= (X + Width)) && (MouseY >= Y && MouseY <= (Y + Height)));
}
Actually, since HighlightedButton is a static member of OButton I could even set it inside the OButton::IsHighlighted() method