March 05, 2021, 07:32:20 AM

Author Topic: [bb] MouseHover() by asdfasdf [ 1+ years ago ]  (Read 582 times)

Offline BlitzBot

[bb] MouseHover() by asdfasdf [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : MouseHover()
Author : asdfasdf
Posted : 1+ years ago

Description : Commands for checking to see if the mouse is over an image

Code :
Code: BlitzBasic
  1. Function MouseHover(image,x,y)
  2.  
  3. If RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21) Then
  4.         Return True
  5. Else
  6.         Return False
  7. EndIf
  8.  
  9. End Function
  10.  
  11. Function MouseClick(image,x,y,button=1)
  12.  
  13. If RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21) And MouseHit(button) Then
  14.         Return True
  15. Else
  16.         Return False
  17. EndIf
  18.  
  19. End Function


Comments :


wizzlefish(Posted 1+ years ago)

 Those are some useful functions, although very simple...it is amazing what simple If statements can do.


Yo! Wazzup?(Posted 1+ years ago)

 Cool. I changed the MouseHit() to MouseDown(), and made a demo for it.
Code: [Select]
Graphics 1280,1024,32,1
image=CreateImage(100,100)
image2=CreateImage(10,10)
SetBuffer ImageBuffer(image)
Oval 1,1,100,100,1
SetBuffer ImageBuffer(image2)
Color 255,0,0
Rect MouseX(),MouseY(),10,10,1
SetBuffer BackBuffer()
While Not KeyDown(1)
Cls
DrawImage image, 1,1
DrawImage image2,MouseX(),MouseY()
Color 255,255,255
ishovering=MouseHover(image,1,1)
isclicked=MouseClick(image,1,1)
If ishovering=True Then
Text 100,100, "Hovering!"
EndIf
If isclicked=True Then
Text 100,112, "Clicked!"
EndIf
Flip
Wend
Function MouseHover(image,x,y)

If RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21) Then
Return True
Else
Return False
EndIf

End Function

Function MouseClick(image,x,y,button=1)

If RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21) And MouseDown(button) Then
Return True
Else
Return False
EndIf

End Function



cYB0rG(Posted 1+ years ago)

 RectsOverlap already return true/false.So, "If" is used for nothing.
Code: [Select]
Function MouseHover(image,x,y)

Return RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21)

End Function

Function MouseClick(image,x,y,button=1)

Return RectsOverlap(x,y,ImageWidth(image),ImageHeight(image),MouseX(),MouseY(),12,21) And MouseHit(button)

End Function



CS_TBL(Posted 1+ years ago)

 wazzup: a function that returns a value can be seen as some kinda variable, e.g. you can directly return it, do math with it, etc.


System4 Studios(Posted 1+ years ago)

 Just what I needed thanks.. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal