// $Revision: 1.7 $ // Copyright (C) 1994 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_REFRESHSUBSYSTEM #include "RefreshSubsystem.h" #endif #ifndef TaligentSamples_CONCURRENTACTORS #include "ConcurrentActors.h" #endif //============================================================================== // MRefreshable MRefreshable::MRefreshable() { } MRefreshable::~MRefreshable() { } void MRefreshable::PreRefresh(const TTime& interval) { } void MRefreshable::PostRefresh(const TTime& interval) { } //................................................................................ static const TSeconds TRefreshThread_kDefaultFrameRate(1.0 / 7.5); const TTime& TRefreshThread::kDefaultFrameRate = TRefreshThread_kDefaultFrameRate; static const TToken TRefreshThread_kRefreshToken("TRefreshThread::kRefreshToken"); const TToken& TRefreshThread::kRefreshToken = TRefreshThread_kRefreshToken; TRefreshThread::TRefreshThread(TGrafPort* port, const TTime& refreshRate) : TPeriodicThread(), fPort(port), fBackground(NIL), fObjects(), fRefreshRate(refreshRate), fRefreshNotifier(), fRefreshInterest(&fRefreshNotifier, kRefreshToken) { } TRefreshThread::~TRefreshThread() { fObjects.RemoveAll(); } void TRefreshThread::Add(MRefreshable* object) { fObjects.AddLast(object); CheckInterval(); } MRefreshable* TRefreshThread::Remove(MRefreshable& object) { MRefreshable* result = fObjects.Remove(object); CheckInterval(); return result; } void TRefreshThread::RemoveAll() { fObjects.RemoveAll(); CheckInterval(); } void TRefreshThread::SetBackground(MRefreshable* background) { fBackground = background; CheckInterval(); } TInterest* TRefreshThread::CreateRefreshInterest() { return new TInterest(fRefreshInterest); } void TRefreshThread::HandleIntervalPassed(const TTime& interval) { if (fBackground != NIL) { fBackground->PreRefresh(interval); fBackground->Draw(*fPort); fBackground->PostRefresh(interval); } TDequeOfIterator iter(&fObjects); MRefreshable* item = iter.First(); while (item != NIL) { item->PreRefresh(interval); item->Draw(*fPort); item->PostRefresh(interval); item = iter.Next(); } fRefreshNotifier.Notify(TNotification(fRefreshInterest)); } void TRefreshThread::GetDelayInterval(TTime& interval) const { if (fObjects.Count() == 0 && fBackground == NIL) { interval = TTime::kPositiveInfinity; } else { interval = fRefreshRate; } }