Forum Navigation
You need to log in to create posts and topics.

Re: PG And PointInRect

Posted by: turovich <turovich@...>

>Hi all, major question is, how would I implement a "clickable rectangle"
>type of thing in a window withouthaving to create a button or object in
>that area?
>
>I would suppose I use PtInRect, but how does that work??
>

When given a mouse point and a rect, PtInRect returns true if the point
is located within the rect, otherwise it returns false. Make sure to
convert the raw global point to the local window coordinates with
GlobalToLocal BEFORE calling PtInRect, else the test will usually fail.

Give this a try:

' PTINRECT EXAMPLE
'
DIM gRect1.8
DIM gRect2.8
END GLOBALS

LOCAL FN HandleMouseEvent
DIM msPt.4
DIM theRect.8
'get mouse event and position
msEvnt% = MOUSE( 0 )
CALL GETMOUSE( msPt )
'PRINT%(20,20) msEvnt%

SELECT msEvnt%
' select type of mouse event
CASE _click1nDrag
' convert mouse pt to local coordinates
CALL GLOBALTOLOCAL( msPt )
' check for click position
SELECT
CASE FN PTINRECT( msPt, gRect1 )
theRect;8 = @gRect1
CASE FN PTINRECT( msPt, gRect2 )
theRect;8 = @gRect2
CASE ELSE
END SELECT
'show we clicked something
CALL INVERTRECT( theRect )
DELAY 500
CALL INVERTRECT( theRect )

CASE ELSE
END SELECT
END FN

LOCAL FN HandleDialogEvent
dlgEvnt% = DIALOG( 0 )
dlgInfo% = DIALOG( dlgEvnt% )

SELECT dlgEvnt%
CASE _wndRefresh
CALL FRAMERECT( gRect1 )
CALL FRAMERECT( gRect2 )

CASE _wndClose
END

CASE ELSE
END SELECT
END FN

WINDOW 1, "PtInRect Example"
TEXT _applFont, 12, 0, 0
CALL SETRECT( gRect1, 20, 40, 120, 140 )
CALL SETRECT( gRect2, 220, 40, 320, 140 )

ON MOUSE FN HandleMouseEvent
ON DIALOG FN HandleDialogEvent

DO
HANDLEEVENTS
UNTIL 0

Hope this helps. -- Frank

______________________________________________________________________
L. Frank Turovich turovich@earthlink.net
Sentient Fruit home.earthlink.net/~turovich
______________________________________________________________________