1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/animation/scheduler.hxx>
24 //////////////////////////////////////////////////////////////////////////////
31 Event::Event(sal_uInt32 nTime
)
41 Event
* Event::GetNext() const
46 void Event::SetNext(Event
* pNew
)
54 sal_uInt32
Event::GetTime() const
59 void Event::SetTime(sal_uInt32 nNew
)
66 } // end of namespace animation
67 } // end of namespace sdr
69 //////////////////////////////////////////////////////////////////////////////
76 EventList::EventList()
81 EventList::~EventList()
86 void EventList::Insert(Event
* pNew
)
90 Event
* pCurrent
= mpHead
;
93 while(pCurrent
&& pCurrent
->GetTime() < pNew
->GetTime())
96 pCurrent
= pCurrent
->GetNext();
101 pNew
->SetNext(pPrev
->GetNext());
102 pPrev
->SetNext(pNew
);
106 pNew
->SetNext(mpHead
);
112 void EventList::Remove(Event
* pOld
)
116 Event
* pCurrent
= mpHead
;
119 while(pCurrent
&& pCurrent
!= pOld
)
122 pCurrent
= pCurrent
->GetNext();
127 pPrev
->SetNext(pOld
->GetNext());
131 mpHead
= pOld
->GetNext();
138 void EventList::Clear()
142 Event
* pNext
= mpHead
->GetNext();
148 Event
* EventList::GetFirst()
152 } // end of namespace animation
153 } // end of namespace sdr
155 //////////////////////////////////////////////////////////////////////////////
162 Scheduler::Scheduler()
169 Scheduler::~Scheduler()
174 void Scheduler::Timeout()
176 // stop timer and add time
178 mnTime
+= mnDeltaTime
;
183 // re-start or stop timer according to event list
187 void Scheduler::triggerEvents()
189 Event
* pNextEvent
= maList
.GetFirst();
193 // copy events which need to be executed to a vector. Remove them from
195 ::std::vector
< Event
* > EventPointerVector
;
197 while(pNextEvent
&& pNextEvent
->GetTime() <= mnTime
)
199 maList
.Remove(pNextEvent
);
200 EventPointerVector
.push_back(pNextEvent
);
201 pNextEvent
= maList
.GetFirst();
204 // execute events from the vector
205 for(::std::vector
< Event
* >::iterator aCandidate
= EventPointerVector
.begin();
206 aCandidate
!= EventPointerVector
.end(); ++aCandidate
)
208 // trigger event. This may re-insert the event to the scheduler again
209 (*aCandidate
)->Trigger(mnTime
);
214 void Scheduler::checkTimeout()
216 // re-start or stop timer according to event list
217 if(!IsPaused() && maList
.GetFirst())
219 mnDeltaTime
= maList
.GetFirst()->GetTime() - mnTime
;
221 if(0L != mnDeltaTime
)
223 SetTimeout(mnDeltaTime
);
233 sal_uInt32
Scheduler::GetTime()
239 void Scheduler::SetTime(sal_uInt32 nTime
)
246 Event
* pEvent
= maList
.GetFirst();
250 // retet event time points
253 pEvent
->SetTime(nTime
);
254 pEvent
= pEvent
->GetNext();
259 // without delta time, init events by triggering them. This will invalidate
260 // painted objects and add them to the scheduler again
268 void Scheduler::InsertEvent(Event
* pNew
)
277 void Scheduler::RemoveEvent(Event
* pOld
)
279 if(pOld
&& maList
.GetFirst())
286 void Scheduler::SetPaused(bool bNew
)
288 if(bNew
!= mbIsPaused
)
294 } // end of namespace animation
295 } // end of namespace sdr
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */