Coder's Guild Mailing List

Need algorithm help (oops read this one instead)

Posted by Frank Hale on 1999-08-29

Okay what I am doing is designing a menu. What I need
help with is determining when the pointer is over an
item. 

Okay I have the pointer coordinates and the item
coordinates on the menu, I need to figure out the
proper algorithm which determines if the pointer is
over an item.

Lets say I have the following:

int pointer_x, pointer_y;
int item_x, item_y;
int menu_width, menu_height;
int item_width, item_height;

How can I use these to make an if statement that tells
me when the pointer is over an item?

What I've been trying is something like this:

if (pointer_x >= item_x && pointer_x <= menu_width &&
    pointer_y >= item_y && pointer_y <= item_height)
{
	// Cool where over an item
}

But that doesn't work.

I'm not worried about knowing which item I'm over
because thats the easy part. I have all my items in a
linked list and determining what one it is, is simple.
I just need help with the algorithm which determines
if my mouse pointer is over an item.

Thanks,
Frank


===
From: Frank Hale
ICQ: 7205161
Webpage: http://jade.netpedia.net/sapphire
Webpage: http://www.linuxstart.com/~frankhale

"Sapphire - a new window manager for X11"
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com