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() : mnTime(0)
40 void Event::SetTime(sal_uInt32 nNew
)
48 bool CompareEvent::operator()(Event
* const& lhs
, Event
* const& rhs
) const
50 return lhs
->GetTime() < rhs
->GetTime();
54 Scheduler::Scheduler()
61 Scheduler::~Scheduler()
66 void Scheduler::Invoke()
68 // stop timer and add time
70 mnTime
+= mnDeltaTime
;
75 // re-start or stop timer according to event list
79 void Scheduler::triggerEvents()
84 // copy events which need to be executed to a vector. Remove them from
86 ::std::vector
< Event
* > aToBeExecutedList
;
88 while(!maList
.empty() && maList
[0]->GetTime() <= mnTime
)
90 Event
* pNextEvent
= maList
.front();
91 maList
.erase(maList
.begin());
92 aToBeExecutedList
.push_back(pNextEvent
);
95 // execute events from the vector
96 ::std::vector
< Event
* >::const_iterator aEnd
= aToBeExecutedList
.end();
97 for(::std::vector
< Event
* >::iterator aCandidate
= aToBeExecutedList
.begin();
98 aCandidate
!= aEnd
; ++aCandidate
)
100 // trigger event. This may re-insert the event to the scheduler again
101 (*aCandidate
)->Trigger(mnTime
);
105 void Scheduler::checkTimeout()
107 // re-start or stop timer according to event list
108 if(!IsPaused() && !maList
.empty())
110 mnDeltaTime
= maList
.front()->GetTime() - mnTime
;
112 if(0L != mnDeltaTime
)
114 SetTimeout(mnDeltaTime
);
126 void Scheduler::SetTime(sal_uInt32 nTime
)
135 // reset event time points
136 for (auto & rEvent
: maList
)
138 rEvent
->SetTime(nTime
);
143 // without delta time, init events by triggering them. This will invalidate
144 // painted objects and add them to the scheduler again
151 void Scheduler::InsertEvent(Event
* pNew
)
157 void Scheduler::RemoveEvent(Event
* pOld
)
161 auto it
= maList
.find(pOld
);
162 if (it
!= maList
.end())
168 void Scheduler::SetPaused(bool bNew
)
170 if(bNew
!= mbIsPaused
)
176 } // end of namespace animation
177 } // end of namespace sdr
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */