News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Check If a point is inside a box/rect region (Manual PointInBox)

Started by kevin, November 12, 2009, 08:43:00 PM

Previous topic - Next topic

kevin

   This mini example demo's how you can manually detect If a point is inside a box/rect region.  

  Note: This is the equivalent of the built in PointInBox function.

PlayBASIC Code: [Select]
   setfps 30

x1=100
y1=200
x2=500
y2=300


BackDropColour=0


Do
; read the mouse position
x=mousex()
y=mousey()

; manually check if it's inside a rect shape
if Check_IF_POint_Inside_Box(X,Y,x1,y1,x2,y2)
BackdropColour=rgb(100,200,50)
else
BackdropColour=0
endif

; draw the screen
Cls BackDropColour


boxc x1,y1,x2,y2,true,rgb(0,255,0)
dot x,y

Sync
loop



Function Check_IF_POint_Inside_Box(MyPointX,MyPointY,x1,y1,x2,y2)
result=false

; check if this point to the right of the boxes left hand side
if MyPointX>=X1

; check if this point to the left of the boxes right hand side
if MyPointX<=X2

; check if our point is within the boxes TOP and BOTTOM limits
if MyPointY>=Y1
if MyPointY<=Y2
result=true
endif
endif
endif
endif


EndFunction result






 
Related To:

   * Toggle The  Mouse Pointer Off When It's Not Moving
   * Storing User Input In Global Types
   * Drag Rectangles/ GUI Selection