Simon L wrote:
I'm creating a GUI which is a bitmap with active areas, so when I paint
the dialog I calculate the rectangles containing objects.
When I get a click event, I want to know which (if any) rectangle
encompasses the click (so I know which object is clicked).
In the past I've created a vector of rectangles and gone though them
one by one testing for PointInRect or whatever but I reckon this is a
bit clunky, and I'm up to 100 or so objects on a screen.
So RECT is my reference to an object
POINT is what I need to test to get an object.
Any thoughts on what sort of collection could do this neatly for me?
Sounds to me like you require some kind of hierarchical representation,
which is probably implicit in the structure of the GUI.
You ask the parent if the point is inside of it's RECT, if not, nothing
has been clicked, if so, you ask the first child, if so, you ask it's
children, if not you ask the next child etc.
Sounds like a simple tree traversal to me, and it sounds like your RECTs
are implicitly defined by each window object.
If you create a vector of RECTs, you lose the hierarchical nature (Z
dimension), many rectangles may match a point, you want the "closest"
one. You also have to manage the vector whenever a window is added or
removed, sounds like a good source of trouble.
I suggest most of this information is already available in the structure
of the GUI elements, and a simple traversal is required.
Correct me if I'm wrong.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...