fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / sdr / animation / scheduler.cxx
blobe2afe89eeb14a6208da8f730d6d1e86cb6e25cd3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <vector>
25 // event class
27 namespace sdr
29 namespace animation
31 Event::Event(sal_uInt32 nTime)
32 : mnTime(nTime),
33 mpNext(0L)
37 Event::~Event()
42 void Event::SetNext(Event* pNew)
44 if(pNew != mpNext)
46 mpNext = pNew;
51 void Event::SetTime(sal_uInt32 nNew)
53 if(mnTime != nNew)
55 mnTime = nNew;
58 } // end of namespace animation
59 } // end of namespace sdr
62 // eventlist class
64 namespace sdr
66 namespace animation
68 EventList::EventList()
69 : mpHead(0L)
73 EventList::~EventList()
75 Clear();
78 void EventList::Insert(Event* pNew)
80 if(pNew)
82 Event* pCurrent = mpHead;
83 Event* pPrev = 0L;
85 while(pCurrent && pCurrent->GetTime() < pNew->GetTime())
87 pPrev = pCurrent;
88 pCurrent = pCurrent->GetNext();
91 if(pPrev)
93 pNew->SetNext(pPrev->GetNext());
94 pPrev->SetNext(pNew);
96 else
98 pNew->SetNext(mpHead);
99 mpHead = pNew;
104 void EventList::Remove(Event* pOld)
106 if(pOld && mpHead)
108 Event* pCurrent = mpHead;
109 Event* pPrev = 0L;
111 while(pCurrent && pCurrent != pOld)
113 pPrev = pCurrent;
114 pCurrent = pCurrent->GetNext();
117 if(pPrev)
119 pPrev->SetNext(pOld->GetNext());
121 else
123 mpHead = pOld->GetNext();
126 pOld->SetNext(0L);
130 void EventList::Clear()
132 while(mpHead)
134 Event* pNext = mpHead->GetNext();
135 mpHead->SetNext(0L);
136 mpHead = pNext;
140 } // end of namespace animation
141 } // end of namespace sdr
144 // scheduler class
146 namespace sdr
148 namespace animation
150 Scheduler::Scheduler()
151 : mnTime(0L),
152 mnDeltaTime(0L),
153 mbIsPaused(false)
157 Scheduler::~Scheduler()
159 Stop();
162 void Scheduler::Invoke()
164 // stop timer and add time
165 Stop();
166 mnTime += mnDeltaTime;
168 // execute events
169 triggerEvents();
171 // re-start or stop timer according to event list
172 checkTimeout();
175 void Scheduler::triggerEvents()
177 Event* pNextEvent = maList.GetFirst();
179 if(pNextEvent)
181 // copy events which need to be executed to a vector. Remove them from
182 // the scheduler
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);
212 Start();
215 else
217 Stop();
222 // #i38135#
223 void Scheduler::SetTime(sal_uInt32 nTime)
225 // reset time
226 Stop();
227 mnTime = nTime;
229 // get event pointer
230 Event* pEvent = maList.GetFirst();
232 if(pEvent)
234 // retet event time points
235 while(pEvent)
237 pEvent->SetTime(nTime);
238 pEvent = pEvent->GetNext();
241 if(!IsPaused())
243 // without delta time, init events by triggering them. This will invalidate
244 // painted objects and add them to the scheduler again
245 mnDeltaTime = 0L;
246 triggerEvents();
247 checkTimeout();
252 void Scheduler::InsertEvent(Event* pNew)
254 if(pNew)
256 maList.Insert(pNew);
257 checkTimeout();
261 void Scheduler::RemoveEvent(Event* pOld)
263 if(pOld && maList.GetFirst())
265 maList.Remove(pOld);
266 checkTimeout();
270 void Scheduler::SetPaused(bool bNew)
272 if(bNew != mbIsPaused)
274 mbIsPaused = bNew;
275 checkTimeout();
278 } // end of namespace animation
279 } // end of namespace sdr
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */