home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-24 | 3.4 KB | 165 lines | [TEXT/CWIE] |
- // CLG_AnimBanner.cp
- //
- // Pane subClass to display an animated sequence of PICTs
- // Uses a Periodical to make the animation happen.
- //
- // 24jul97 bh
- //****************************************************************************
-
- #ifdef PowerPlant_PCH
- #include PowerPlant_PCH
- #endif
-
- // system headers
- #include <Script.h>
-
- // PowerPlant headers
- #include <LStream.h>
- #include <UDrawingState.h>
-
- // project headers
- #include "LG_Constants.h"
- #include "CLG_AnimBanner.h"
-
-
- //****************************************************************************
- #define kBasePICT 990
- #define kNumPICTs 8
- #define kDrawTime (30*1)
-
-
- //***********************
- // CreateDisplayStream
- //****************************************************************************
- CLG_AnimBanner*
- CLG_AnimBanner::CreateDisplayStream(
- LStream *inStream)
- {
- return (new CLG_AnimBanner(inStream));
- }
-
-
- //***********************
- // CLG_AnimBanner
- //****************************************************************************
- CLG_AnimBanner::CLG_AnimBanner(void)
- {
- this->Init();
- return;
- }
-
- //***********************
- // CLG_AnimBanner
- //****************************************************************************
- CLG_AnimBanner::CLG_AnimBanner( LStream *inStream)
- : LPane( inStream)
- {
- this->Init();
- return;
- }
-
- //***********************
- // Init
- //****************************************************************************
- void CLG_AnimBanner::Init(void)
- {
- mLastDraw = TickCount();
- mCurInd = kNumPICTs-1;
- mAnimOn = false;
- mCurPicH = (PicHandle)GetResource( 'PICT', kBasePICT+mCurInd);
-
- this->StartIdling();
-
- return;
- }
-
-
- //***********************
- // ClickSelf
- //****************************************************************************
- void
- CLG_AnimBanner::ClickSelf( const SMouseDownEvent &inMouseDown)
- {
- mAnimOn = !mAnimOn;
- return;
- }
-
- //***********************
- // SpendTime
- //
- // OK, run through a sequence of PICTs, drawing each one after some
- // constant delay. Special case the last pair and alternate for
- // some random time. Stall afer the sequence to give the user a break!
- //
- //****************************************************************************
- void
- CLG_AnimBanner::SpendTime(
- const EventRecord& inMacEvent)
- {
-
- if ( mAnimOn && TickCount() >= mLastDraw + kDrawTime) {
-
- if ( mCurInd == kNumPICTs) {
- if ( Random() % 16 == 0) {
- mCurInd = 0;
- mLastDraw = TickCount() + 60*5;
- } else mCurInd--;
- } else
- mCurInd++;
-
-
- mCurPicH = (PicHandle)GetResource( 'PICT', kBasePICT+mCurInd);
- mLastDraw = TickCount();
- this->Refresh();
- }
-
- return;
- }
-
- //***********************
- // AdjustCursorSelf
- //****************************************************************************
- void
- CLG_AnimBanner::AdjustCursorSelf(
- Point inPortPt ,
- const EventRecord& inMacEvent)
- {
- Point tPt;
- static Rect savR = {0,0,0,0};
-
- tPt = inPortPt;
-
- CursHandle theCursH = ::GetCursor( 2);
- if (theCursH != nil) {
- ::SetCursor(*theCursH);
- }
- }
-
-
- //***********************
- // DrawSelf
- //****************************************************************************
-
- void CLG_AnimBanner::DrawSelf(void)
- {
- Rect dstR;
- SDimension16 tFrame;
-
- GetFrameSize( tFrame);
-
- dstR.left = mFrameLocation.h;
- dstR.top = mFrameLocation.v;
- dstR.right = dstR.left + tFrame.width;
- dstR.bottom = dstR.top + tFrame.height;
-
- long t = TickCount();
- while ( t == TickCount()) ;
-
- if ( mCurPicH != 0)
- DrawPicture( mCurPicH, &dstR);
-
- return;
- }
-
- //*****************************************************************************
-