Nathanael Noblet wrote:
> Background:
>       So I'm working on a project that is using DirectFB as its "windowing" 
> environment. The interface is pretty much just an image with a few 
> areas that are "hot", there are about 3-6 screens, each with their own 
> hot areas.
> 
> Problem:
>       I need a quick way to determine which hot area was clicked on and call 
> it's function. So I'm wondering what data structure would I use so that 
> once I figure out the location of the click, I can quickly retrieve the 
> function call? I mean, if I have an array, how do I index it in such a 
> way that I can calculate the location of the mouse click to be an index 
> of this array?

How about a sparse array, returning a function pointer or NULL.
This would require you to place all the coordinates of the various hot
spots into the sparse array.

Depending on the shapes of the hot spots, you could also create various
shape stuctures/types that have corresponding functions/methods that know
how to test for inclusion.  You could have a list of each of these shapes
for each screen, ordered by decreasing area of the shape, which you would
iterate through for each mouse click, testing to see if the click location
is on a hot spot.

Dave

Reply via email to