[bb] Hotspots! by cyberseth [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Hotspots!
Author : cyberseth
Posted : 1+ years ago

Description : I finally found a way to do hotspots. The problem came with finding the precise coordinate of the client area of a window, but I discovered that this could be achieved by flicking the mouse there and back in the blink of a millisecond! Anyway, try out this test, you WILL be pleasantly surprised!

Code :
Code (blitzbasic) Select
Type hotspot
Field x,y,width,height
Field clx,cly,win
End Type

win = CreateWindow("Testing!",100,100,200,200,0)
h.hotspot = CreateHotSpot(10,10,150,40,win)
lbltest = CreateTextField(10,10,150,40,win)
lbltest2 = CreateLabel("BOO!",10,60,100,40,win)
SetGadgetText lbltest,"Move your mouse here!"

Repeat
If WaitEvent(1)=$803 Or KeyHit(1) Then End
If MouseOverHotSpot(h)
ShowGadget lbltest2
Else
HideGadget lbltest2
End If
Forever


Function CreateHotSpot.hotspot(x,y,width,height,window)
; -- In the blink of an instant.. Find out the client X,Y offsets --
tmpcan = CreateCanvas(0,0,1,1,window)
xx=MouseX() yy=MouseY()
MoveMouse 0,0,tmpcan
clx=MouseX() cly=MouseY()
MoveMouse GadgetX(window),GadgetY(window)
clx=clx-MouseX() cly=cly-MouseY()
MoveMouse xx,yy
FreeGadget tmpcan
; -- Now make the hotspot area and save the X,Y offsets --
h.hotspot = New hotspot
hx=x  hy=y
hwidth=width hheight=height
hclx=clx  hcly=cly
hwin = window
Return h
End Function

Function MouseOverHotSpot(h.hotspot)
x=GadgetX(hwin)+hclx+hx ;Window x,y + borderclient offset + hotspot x,y
y=GadgetY(hwin)+hcly+hy
Return RectsOverlap(MouseX(),MouseY(),1,1,x,y,hwidth,hheight)
End Function


Comments :


TAS(Posted 1+ years ago)

 Very neat