Ooops
October 19, 2021, 10:53:50

Author Topic: [bb] Hotspots! by cyberseth [ 1+ years ago ]  (Read 696 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Hotspots! by cyberseth [ 1+ years ago ]
« on: June 29, 2017, 00:28:40 »
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
  1. Type hotspot
  2.         Field x,y,width,height
  3.         Field clx,cly,win
  4. End Type
  5.  
  6. win = CreateWindow("Testing!",100,100,200,200,0)
  7. h.hotspot = CreateHotSpot(10,10,150,40,win)
  8. lbltest = CreateTextField(10,10,150,40,win)
  9. lbltest2 = CreateLabel("BOO!",10,60,100,40,win)
  10. SetGadgetText lbltest,"Move your mouse here!"
  11.  
  12. Repeat
  13.         If WaitEvent(1)=$803 Or KeyHit(1) Then End
  14.         If MouseOverHotSpot(h)
  15.                 ShowGadget lbltest2
  16.         Else
  17.                 HideGadget lbltest2
  18.         End If
  19. Forever
  20.  
  21.  
  22. Function CreateHotSpot.hotspot(x,y,width,height,window)
  23.         ; -- In the blink of an instant.. Find out the client X,Y offsets --
  24.         tmpcan = CreateCanvas(0,0,1,1,window)
  25.         xx=MouseX() yy=MouseY()
  26.         MoveMouse 0,0,tmpcan
  27.         clx=MouseX() cly=MouseY()
  28.         MoveMouse GadgetX(window),GadgetY(window)
  29.         clx=clx-MouseX() cly=cly-MouseY()
  30.         MoveMouse xx,yy
  31.         FreeGadget tmpcan
  32.         ; -- Now make the hotspot area and save the X,Y offsets --
  33.         h.hotspot = New hotspot
  34.         hx=x  hy=y
  35.         hwidth=width hheight=height
  36.         hclx=clx  hcly=cly
  37.         hwin = window
  38.         Return h
  39. End Function
  40.  
  41. Function MouseOverHotSpot(h.hotspot)
  42.         x=GadgetX(hwin)+hclx+hx ;Window x,y + borderclient offset + hotspot x,y
  43.         y=GadgetY(hwin)+hcly+hy
  44.         Return RectsOverlap(MouseX(),MouseY(),1,1,x,y,hwidth,hheight)
  45. End Function


Comments :


TAS(Posted 1+ years ago)

 Very neat


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal