[futurebasic] Re: [FB] Carbon Differences ( updating some Derek code)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2003 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sat, 10 May 2003 16:31:17 +1200
On Saturday, May 10, 2003, at 04:52  AM, michael evans wrote:

>> Use RezLib. It's a freeware shared library by Ian Ollman that does
>> monitor fades and resolution switching in OS 8/9 and in OS X.  I don't
>> have an up-to-date URL, but a Google search will find it.

> Easy for you to say...
>
> But for those of us with small brains who haven't a clue how to use a 
> shared
> library or even to set up the data types from the C header files it's 
> quite
> mysterious.


The demo below should get you started. There are many more RezLib 
functions defined in the RezLib shared library and discussed in the 
RezLib documentation, but I haven't included their FB conversions here.

Robert P.



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

/*
"RezLib is an attempt to unify display color depth and resolution
switching, gamma fading, and vertical retrace synchronization
under a common API for both MacOS 8/9 and MacOS X. It is provided
free of charge as a shared library for use under Carbon."

This tiny RezLib demo shows a fade on the main screen,
and some info gathered by GetCurrentSetting.

After obtaining RezLib, either put a copy in the app's folder, or
(in the case of an FB^3 project) drag its icon to the Project window.

Robert P.   10 May 2003
*/


// RezLib declarations

begin record RLInfo
dim as UInt32   resolutionID
dim as UInt32   refreshRate   // 16.16 fixed point in Hz
dim as UInt32   height
dim as UInt32   width
dim as UInt32   colorDepths
dim as UInt16   flags
dim as Boolean  isSafe
dim as char     rlInfoType    // Reserved. Pass 0 here.
dim as Str31    name
end record

// ScreenRef is a opaque pointer to a class that handles one display.
#define ScreenRef as long

_kGammaTableEntryCount = 256
begin record RLGammaTable
dim as single red[_kGammaTableEntryCount - 1]
dim as single green[_kGammaTableEntryCount - 1]
dim as single blue[_kGammaTableEntryCount - 1]
end record

library "RezLib"

// these are only some of RezLib's functions
toolbox fn NewScreenRef( const Rect *where, OSStatus *error ) = 
ScreenRef
toolbox fn GetCurrentSetting( ScreenRef screen, RLInfo *info ) = 
OSStatus
toolbox fn GetGamma( ScreenRef screen, RLGammaTable *gamma ) = OSStatus

// The 'seconds' parameter here should be a float (i.e. FB single),
// but we define it as double to overcome a limitation of FB,
// which cannot pass singles to a toolbox routine.
toolbox fn FadeToGamma( ScreenRef screen, const RLGammaTable *gamma, ¬
    double seconds ) = OSStatus
toolbox fn FadeToColor( ScreenRef screen, const RGBColor *color, ¬
    double seconds ) = OSStatus

library

end globals



// main program
dim as OSStatus     @ err
dim as ScreenRef      mainScreenRef
dim as RLGammaTable   originalGamma
dim as RGBColor       fadeColor
dim as RLInfo         currentScreenInfo

long if ( fn FBTestForLibrary( "RezLib" ) == _false )
shutdown "RezLib not found"
end if

mainScreenRef = fn NewScreenRef( #_nil, @err )
if ( err != _noErr ) then shutdown "Error in NewScreenRef"

err = fn GetGamma( mainScreenRef, @originalGamma )
fadeColor.red = 20000 : fadeColor.green = 0 : fadeColor.blue = 0
// fade out to dark red  over 2 seconds
err = fn FadeToColor( mainScreenRef, fadeColor, 2.0 )
window 1, "RezLib Test"

// Get information about the current screen setting
// You must set the rlInfoType variable to zero
currentScreenInfo.rlInfoType = 0
err = fn GetCurrentSetting( mainScreenRef, @currentScreenInfo )

long if ( err )
print "GetCurrentSetting returned error " err
xelse
print "width  = " currentScreenInfo.width
print "height = " currentScreenInfo.height
print "depth  = " currentScreenInfo.colorDepths
print "name   = " currentScreenInfo.name
// Note: in OS X some monitors stupidly report 0 Hz
print "refreshRate = " currentScreenInfo.refreshRate >> 16 " Hz"
end if
// fade in to original over 1.5 seconds
err = fn FadeToGamma( mainScreenRef, @originalGamma, 1.5 )

do
HandleEvents
until 0