[futurebasic] Re: [FB] Temporary alert window

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2011 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Sat, 9 Jul 2011 12:38:32 +0100
Robert P wrote:

> Steve VV sent some improvements to my original attempt, the most surprising of which makes the window a naked drawer (for its rounded corners). A few more tweaks gave the handsome result below.
> 
> The original request from my collaborator was for "...a cool state-of-the art transparent window, like the volume control functions...". Perhaps he will let us know if the problem is sufficiently well solved: similar in spirit to the system mouse 'Connection Loss' alert, but commendably free of slavish imitation.

I don't use a mouse so have no idea what the 'Connection Loss' alert looks like, but if the OP prefers something like the volume control up/down thingy...
'------------
#if compilerversion < 167
toolbox fn SetWindowAlpha( WindowRef inWindow, CGFloat inAlpha ) = OSStatus
toolbox fn GetWindowAlpha( WindowRef inWindow, CGFloat * outAlpha ) = OSStatus
#endif

begin record TempAlertRec
dim as WindowRef  w 
dim as ProcessSerialNumber frontPSN
end record

_taWndNum = 135762 // arbitrary unique value
_taHeight = 140 : _taWidth = 250
_taBottomMargin = 60


local fn TemporaryAlertHandler( theTimer as EventLoopTimerRef, userData as pointer )
'~'1
dim as ^TempAlertRec  info : info = userData
dim as CGFloat        alpha

fn GetWindowAlpha( info.w, @alpha )
long if ( alpha < 0.1 )
fn RemoveEventLoopTimer( theTimer )
window close _taWndNum
fn SetFrontProcess( info.frontPSN ) // restore original process
free( info )
xelse
fn SetWindowAlpha( info.w, alpha - 0.025 ) // fade
end if
end fn


local fn TemporaryAlert( msg as Str255, explanation as Str255 )
'~'1
dim as ^TempAlertRec        info
dim as long                 height, wdth
dim as Rect                 r
dim as ProcessSerialNumber  ourPSN
dim as ControlFontStyleRec  cfs
dim as RGBColor             fore, back

info = fn malloc( sizeof( TempAlertRec ) )
fn GetFrontProcess( @info.frontPSN ) // save original process
height = system( _scrnHeight ) : wdth = system( _scrnWidth )
SetRect( @r, (wdth - _taWidth)/2, height - _taHeight - _taBottomMargin, (wdth + _taWidth)/2, height - _taBottomMargin ) 
appearance window _taWndNum,, @r, _kOverlayWindowClass
get window _taWndNum, info.w
fore.red = 28000 : fore.green = 28000 : fore.blue = 28000
RGBForeColor( @fore )
SetRect( @r, 0, 0, _taWidth, _taHeight )
PaintRoundRect( @r, 20, 20 )
fn SetWindowAlpha( info.w, 0.8 )
SetRect( @r, 20, 0, _taWidth - 20, _taHeight/2 )
appearance button 1,,,,,,@r, _kControlStaticTextProc
fore.red = -1 : fore.green = -1 : fore.blue = -1 // white
back.red = 28000 : back.green = 28000 : back.blue = 28000 // gray
cfs.flags = _kControlUseFaceMask _kControlUseSizeMask _kControlUseJustMask _kControlUseForeColorMask _kControlUseBackColorMask
cfs.size = 17 : cfs.style = _boldBit% : cfs.just = _teCenter : cfs.foreColor = fore : cfs.backColor = back
fn SetButtonFontStyle( 1, cfs )
fn SetButtonTextString( 1, chr$( 13 ) + msg  )
SetRect( @r, 20, _taHeight/2, _taWidth - 20, _taHeight )
appearance button 2,,,,,,@r, _kControlStaticTextProc
cfs.style = 0
fn SetButtonFontStyle( 2, cfs )
fn SetButtonTextString( 2, explanation )
fn InstallEventLoopTimer( fn GetMainEventLoop(), 3.0, 0.02, @fn TemporaryAlertHandler, #info, 0 )
ourPSN.lowLongOfPSN = _kCurrentProcess : ourPSN.highLongOfPSN = 0
fn SetFrontProcess( @ourPSN ) // ensure we are front
end fn


fn TemporaryAlert( "Alas!", "Something happened" )
HandleEvents
'------------