Walter Lenk wrote: > I have been working on an ADHD evaluation project for some years > now, and the researcher has asked me to reverse (horizontally) the > sense of some of the program's instruction screens - they will be > seen by the subject (in an MRI machine) via a mirror. My initial > solution was to create and then store a 'flipped' version of the > PICT resource that had a different ID number, to be called when > needed. Since speed is not critical for presenting these > instruction screens, I thought that a more elegant solution might > be to flip the original PICTs 'on the fly'. Anybody have any idea > how this might be done? > > I am loading each PICT with: > LET pict& = FN GETPICTURE(pictID) > and after processing it into an offscreen GWorld, I am then showing > it with: > CALL DRAWPICTURE(pict&,rect1) > This project was started under OS9, and has since been migrated to > OSX. I am under the impression that the double screen buffering > that OSX does has rendered the original need for the offscreen > GWorld unnecessary. Yes? See FlipGWorldHoriz below. Keep that GWorld! I don't understand why, or even how, you would draw your GWorld with DrawPicture. CopyBits (typically placed in a wrapper such as CopyGWtoGW below) does it all. Robert P. '------------------------------------ toolbox fn GetPixRowBytes( PixMapHandle pm ) = long local mode local fn MakeGWorld( r as ^Rect ) '~'1 dim @ myGWorld as CGrafPtr if ( fn NewGWorld( @myGWorld, 32, #r, 0, 0, 0 ) != _noErr ) ¬ then stop "NewGWorld error" end fn = myGWorld _message$ = "Hello GWorld!" local mode local fn SillyDrawing( r as ^Rect ) '~'1 EraseRect( #r ) TextSize( 72 ) MoveTo( (r.right - fn StringWidth(_message$ ))/2 , r.bottom/2 ) DrawString( _message$ ) end fn local mode local fn CopyGWtoGW( srcGW as CGrafPtr, srcRect as ^Rect, destGW as CGrafPtr, destRect as ^Rect ) '~'1 long if ( fn LockPixels( fn GetGWorldPixMap( srcGW ) ) ) ForeColor( _blackColor ) BackColor( _whiteColor ) CopyBits( #srcGW + 2, #destGW + 2, #srcRect, #destRect, _srcCopy, 0 ) UnlockPixels( fn GetGWorldPixMap( srcGW ) ) end if end fn local mode local fn FlipGWorldHoriz( theGW as CGrafPtr ) '~'1 dim as long y, xR, xL, tempPixel, rowBytes dim as pointer baseAddr, pixAddrL, pixAddrR dim as Rect bounds dim pmHandle as ^^PixMap dim as short depth pmHandle = fn GetGWorldPixMap( theGW ) rowBytes = fn GetPixRowBytes( pmHandle ) depth = pmHandle..pixelSize if ( depth != 32 ) then stop "FlipGWorldHoriz needs 32-bit depth" baseAddr = fn GetPixBaseAddr( pmHandle ) bounds = pmHandle..bounds y = 0 while ( y < bounds.bottom ) xL = 0 xR = bounds.right - 1 while ( xL < xR ) // swap pixels at xL and xR pixAddrL = baseAddr + (xL << 2) pixAddrR = baseAddr + (xR << 2) tempPixel = pixAddrL.0& pixAddrL.0& = pixAddrR.0& pixAddrR.0& = tempPixel xL++ xR-- wend baseAddr += rowBytes y++ wend end fn dim as CGrafPtr @ windGW, imageGW dim as Handle @ currDev dim as Rect r window 1 GetGWorld( @windGW, @currDev ) SetRect( r, 0, 0, window( _width ), window(_height) ) imageGW = fn MakeGWorld( r ) SetGWorld( imageGW, 0 ) fn SillyDrawing( r ) fn FlipGWorldHoriz( imageGW ) SetGWorld( windGW, currDev ) fn CopyGWtoGW( imageGW, r, windGW, r ) do HandleEvents until ( 0 ) '--------------------------