what is missing however is returning false if the gadget is hidden or disabled.
Also performance wise it's a bit worse off than a platform implementation obviously.
Ideally the PureBasic team would implement this into PureBasic utilizing PureBasic's own internal states, since MouseX and MouseY is already tracked a native code could avoid those two calls and would also have the hidden and disabled states available as well as quick access to the gadget x,y,w,h stored info so performance wise a native feature could perform as good as or better than a platform specific implementation, and it would even work with imagegadgets on Linux GTK etc.
For us such a feature would simply be using either:
gadget=GetHoverGadget()
or:
truefalse=GetGadgetHoverState(gadget)
or:
SetGadgetHoverCallback(@procedure())
+
Procedure hover_callback(gadget,mousex,mousey)
;we do something here
EndProcedure
A callback would give best performance as there would be no need to update internal states if the callback is not used.
GetGadgetHoverState() would be very similar to the example below.
GetHoverGadget() has the potential of the lowest overhead next to the callback.
Anyway, here ya go:
Code: Select all
Macro GadgetHoverCheck(windowmousex,windowmousey,gadget)
(((Not windowmousex<GadgetX(gadget))&(Not windowmousey<GadgetY(gadget)))&(Not windowmousex>=(GadgetX(gadget)+GadgetWidth(gadget)))&(Not windowmousey>=(GadgetY(gadget)+GadgetHeight(gadget))))
EndMacro
;Example
#Window1=1
#Gadget1=1
#Gadget2=2
Define x.l,y.l,oldx.l,oldy.l
OpenWindow(#Window1,0,0,400,100,"Crossplatform MouseOver example",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(#Gadget1,10,10,380,20,"Button 1")
ButtonGadget(#Gadget2,10,30,380,20,"Button 2")
Repeat
event=WaitWindowEvent(1)
If event
x=WindowMouseX(#Window1)
y=WindowMouseY(#Window1)
If (oldx<>x) Or (oldy<>y)
If GadgetHoverCheck(x,y,#Gadget1)
SetGadgetText(#Gadget1,"Hover")
Else
SetGadgetText(#Gadget1,"Button 1")
EndIf
If GadgetHoverCheck(x,y,#Gadget2)
SetGadgetText(#Gadget2,"Hover")
Else
SetGadgetText(#Gadget2,"Button 2")
EndIf
oldx=x
oldy=y
EndIf
EndIf
Until event=#PB_Event_CloseWindow