How I check for mouse over

BlitzMax Forums/BlitzMax Beginners Area/How I check for mouse over

Newbie(Posted 2007) [#1]
I have this code I use to check if an icon is selected -> hence, if the mouse is OVER a specific area of the screen
(i use this in my main loop while reading mousex() and mousey()

Local x1: Int = X_of_image
Local x2: Int = X_of_image+ width_of_Image
Local y1: Int = Y_of_image
Local y2: Int = y_of_image + height_of_image

If MouseX() > x1 And MouseX() < x2
If MouseY() > y1 And MouseY() < y2
...
DO SOMETHING! WE ARE OVER THE AREA
...
EndIf
EndIf '
is there a smarter way? and for the standard windows mouse pointer will this trigger only, and only when the upper left corner of the mouse is within the area?


tonyg(Posted 2007) [#2]
Didn't the code here help?


Newbie(Posted 2007) [#3]
that code does the exact same thing as above as far as I can see


tonyg(Posted 2007) [#4]
that code does the exact same thing as above as far as I can see

but in
a smarter way
.
The smartest way would probably be to use colliderect.


Newbie(Posted 2007) [#5]
how is it smarter?


tonyg(Posted 2007) [#6]
You create/register your rects (or images or buttons or icons or whatever) and then simply call it once each loop. The way you've suggested to do it will make it difficult to add more checks and bloat the mainloop.


GfK(Posted 2007) [#7]
Its smarter because the documentation says it is. Have a look! ;)


TomToad(Posted 2007) [#8]
I just created an Icon type for managing Icons in your program. I posted it in the archives if you think you can find use for it.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1926