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>
31 Event::Event(sal_uInt32 nTime
)
42 void Event::SetNext(Event
* pNew
)
51 void Event::SetTime(sal_uInt32 nNew
)
58 } // end of namespace animation
59 } // end of namespace sdr
68 EventList::EventList()
73 EventList::~EventList()
78 void EventList::Insert(Event
* pNew
)
82 Event
* pCurrent
= mpHead
;
85 while(pCurrent
&& pCurrent
->GetTime() < pNew
->GetTime())
88 pCurrent
= pCurrent
->GetNext();
93 pNew
->SetNext(pPrev
->GetNext());
98 pNew
->SetNext(mpHead
);
104 void EventList::Remove(Event
* pOld
)
108 Event
* pCurrent
= mpHead
;
111 while(pCurrent
&& pCurrent
!= pOld
)
114 pCurrent
= pCurrent
->GetNext();
119 pPrev
->SetNext(pOld
->GetNext());
123 mpHead
= pOld
->GetNext();
130 void EventList::Clear()
134 Event
* pNext
= mpHead
->GetNext();
140 } // end of namespace animation
141 } // end of namespace sdr
150 Scheduler::Scheduler()
157 Scheduler::~Scheduler()
162 void Scheduler::Invoke()
164 // stop timer and add time
166 mnTime
+= mnDeltaTime
;
171 // re-start or stop timer according to event list
175 void Scheduler::triggerEvents()
177 Event
* pNextEvent
= maList
.GetFirst();
181 // copy events which need to be executed to a vector. Remove them from
183 ::std::vector
< Event
* > EventPointerVector
;
185 while(pNextEvent
&& pNextEvent
->GetTime() <= mnTime
)
187 maList
.Remove(pNextEvent
);
188 EventPointerVector
.push_back(pNextEvent
);
189 pNextEvent
= maList
.GetFirst();
192 // execute events from the vector
193 for(::std::vector
< Event
* >::iterator aCandidate
= EventPointerVector
.begin();
194 aCandidate
!= EventPointerVector
.end(); ++aCandidate
)
196 // trigger event. This may re-insert the event to the scheduler again
197 (*aCandidate
)->Trigger(mnTime
);
202 void Scheduler::checkTimeout()
204 // re-start or stop timer according to event list
205 if(!IsPaused() && maList
.GetFirst())
207 mnDeltaTime
= maList
.GetFirst()->GetTime() - mnTime
;
209 if(0L != mnDeltaTime
)
211 SetTimeout(mnDeltaTime
);
223 void Scheduler::SetTime(sal_uInt32 nTime
)
230 Event
* pEvent
= maList
.GetFirst();
234 // retet event time points
237 pEvent
->SetTime(nTime
);
238 pEvent
= pEvent
->GetNext();
243 // without delta time, init events by triggering them. This will invalidate
244 // painted objects and add them to the scheduler again
252 void Scheduler::InsertEvent(Event
* pNew
)
261 void Scheduler::RemoveEvent(Event
* pOld
)
263 if(pOld
&& maList
.GetFirst())
270 void Scheduler::SetPaused(bool bNew
)
272 if(bNew
!= mbIsPaused
)
278 } // end of namespace animation
279 } // end of namespace sdr
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */