// In the example three different colored segments are drawn.
// When the left mouse button clicks in a segment, the priority
// of the applicable segment is placed first so that the
// clicked segment is brought into the foreground.
// By pressing F10, values for the size of the sensitive
// rectangle around the mouse pointer used to find the
// segments can be changed.
#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"
PROCEDURE Main
LOCAL nBox1, nBox2, nArc, aAttr, aColor, bSetColor
LOCAL aSegment, aFound, mp1, mp2, nEvent := xbe_None
LOCAL GetList := {}, nX, nY
CLS
// area attributes for
aAttr := Array( GRA_AA_COUNT ) // circle and box
aAttr [ GRA_AA_SYMBOL ] := GRA_SYM_HALFTONE
// code block to change color
bSetColor := {|nColor| aAttr [ GRA_AA_COLOR ] := nColor, ;
GraSetAttrArea( NIL, aAttr ) }
// graphic mouse coordinates
SetAppWindow():mouseMode := XBPCRT_MOUSEMODE_PM
SetMouse(.T.) // activate mouse
aSegment := {}
aColor := { GRA_CLR_RED, GRA_CLR_GREEN, GRA_CLR_BLUE }
AAdd( aSegment, GraSegOpen( NIL, GRA_SEG_MODIFIABLE ) )
Eval( bSetColor, aColor[1] ) // create segments (red box)
GraBox( NIL, { 80,120}, {200,200}, GRA_FILL )
GraSegClose()
AAdd( aSegment, GraSegOpen( NIL, GRA_SEG_MODIFIABLE ) )
Eval( bSetColor, aColor[2] ) // green box
GraBox( NIL, {150, 70}, {330,150}, GRA_FILL )
GraSegClose()
AAdd( aSegment, GraSegOpen( NIL, GRA_SEG_MODIFIABLE ) )
Eval( bSetColor, aColor[3] ) // blue circle
GraArc( NIL, {120,100}, 80,,,, GRA_FILL )
GraSegClose()
DO WHILE nEvent <> xbeM_RbClick // cancel with right mouse click
nEvent := AppEvent( @mp1, @mp2,,0 )
IF nEvent == xbeM_LbDown // left mouse click
aFound := GraSegFind(NIL, mp1 )
@ MaxRow(),0 SAY Space(80)
IF ! Empty( aFound ) // segment in foreground
GraSegPriority( NIL, aFound[1], 0, GRA_SEG_HIGHER_PRI )
GraSegDraw( NIL, aFound[1] )
SetPos( MaxRow(), 0 )
Aeval( aFound, {|n| QQout(n)} )
ENDIF
ELSEIF nEvent == xbeK_F10 // input new values
SetMouse(.F.) // deactivate mouse
nX := 16 // for input
nY := 8
SetCursor(1)
@ 0,0 SAY "Resolution in X:" GET nX PICTURE "99"
@ 1,0 SAY "Resolution in Y:" GET nY PICTURE "99"
READ
SetCursor(0)
SetMouse(.T.)
IF Updated() // resize sensitive region
GraSegPickResolution( , , {nX,nY} )
ENDIF
ENDIF
ENDDO
RETURN