[futurebasic] Re: [FB] Convert Region to CGPath or just get a points list?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2004 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Fri, 16 Apr 2004 08:45:39 +1200
Robert Covington wrote:

> Is there any way in this new hades of opaque region handles to convert 
> a region to a path?

> Can a points/polygon list be extracted these days from the newfangled, 
> "opaque" region handles?

'-------

'~'A
'                           CPU : Carbon
'                    CALL Req'd : Off
'~'B

/* How to dissect a region into Rects
Robert P.  April 2004 */

#define RegionToRectsUPP as proc
toolbox fn NewRegionToRectsUPP( proc ) = proc

#define QDRegionParseDirection as SInt32
toolbox fn QDRegionToRects( RgnHandle rgn, ¬
    QDRegionParseDirection dir, ¬
    RegionToRectsUPP proc, Ptr userData ) = OSStatus

_kQDRegionToRectsMsgInit       = 1
_kQDRegionToRectsMsgParse      = 2
_kQDRegionToRectsMsgTerminate  = 3

_kQDParseRegionFromTop         = 1
_kQDParseRegionFromBottom      = 2
_kQDParseRegionFromLeft        = 4
_kQDParseRegionFromRight       = 8
_kQDParseRegionFromTopLeft     = 5
_kQDParseRegionFromBottomRight = 10



long if 0
"EnumerateRectProc"
enterproc fn EnumerateRectProc( message as UInt16, rgn as RgnHandle,¬
     r as ^Rect, userData as long ) = OSStatus
'~'1
dim as RGBColor  rgb
dim as long      x, y, mag

select message
case _kQDRegionToRectsMsgInit
// you could allocate something here
case _kQDRegionToRectsMsgParse
// got a Rect; display it in a random colour
rgb.red   = rnd( 48000 )
rgb.green = rnd( 48000 )
rgb.blue  = rnd( 48000 )
RGBForeColor( @rgb )
mag = userData
PenSize( mag, mag )
y = r.top
while ( y < r.bottom )
x = r.left
while ( x < r.right )
MoveTo( x*mag, y*mag )
call Line( 0, 0 )
x++
wend
y++
wend
case _kQDRegionToRectsMsgTerminate
// you could de-allocate something here
end select
end fn = _noErr
end if


local fn DisplayAsRects ( rgn as RgnHandle, magnification as long )
'~'1
begin globals
dim as RegionToRectsUPP  sEnumerateRectProc
end globals

if ( sEnumerateRectProc == 0 ) then ¬
    sEnumerateRectProc = fn NewRegionToRectsUPP( ¬
    [proc "EnumerateRectProc" + _FBprocToProcPtrOffset]  )
end fn = fn QDRegionToRects( rgn, _kQDParseRegionFromTopLeft, ¬
    sEnumerateRectProc, magnification )


dim as RgnHandle  rgn1, rgn2
dim as Rect       r

window 1
rgn1 = fn NewRgn
rgn2 = fn NewRgn

// make two circular regions...
SetRect( r, 10, 10, 30, 30 )
OpenRgn
FrameOval( r )
CloseRgn( rgn1 )
OffsetRect( r, 10, 10 )
InsetRect( r, -2, -2 )
OpenRgn
FrameOval( r )
CloseRgn( rgn2 )
//...and xor them
XorRgn( rgn1, rgn2, rgn1 )

PaintRgn( rgn1 )
fn DisplayAsRects( rgn1, 4 )

do
HandleEvents
until 0
'-------