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>
28 namespace sdr::animation
30 Event::Event() : mnTime(0)
39 void Event::SetTime(sal_uInt32 nNew
)
47 Scheduler::Scheduler()
52 SetPriority(TaskPriority::POST_PAINT
);
55 Scheduler::~Scheduler()
60 void Scheduler::Invoke()
62 // stop timer and add time
64 mnTime
+= mnDeltaTime
;
69 // re-start or stop timer according to event list
73 void Scheduler::triggerEvents()
78 // copy events which need to be executed to a vector. Remove them from
80 ::std::vector
< Event
* > aToBeExecutedList
;
82 while(!mvEvents
.empty() && mvEvents
.front()->GetTime() <= mnTime
)
84 Event
* pNextEvent
= mvEvents
.front();
85 mvEvents
.erase(mvEvents
.begin());
86 aToBeExecutedList
.push_back(pNextEvent
);
89 // execute events from the vector
90 for(auto& rpCandidate
: aToBeExecutedList
)
92 // trigger event. This may re-insert the event to the scheduler again
93 rpCandidate
->Trigger(mnTime
);
97 void Scheduler::checkTimeout()
99 // re-start or stop timer according to event list
100 if(!IsPaused() && !mvEvents
.empty())
102 mnDeltaTime
= mvEvents
.front()->GetTime() - mnTime
;
106 SetTimeout(mnDeltaTime
);
118 void Scheduler::SetTime(sal_uInt32 nTime
)
124 if (mvEvents
.empty())
127 // reset event time points
128 for (auto & rEvent
: mvEvents
)
130 rEvent
->SetTime(nTime
);
135 // without delta time, init events by triggering them. This will invalidate
136 // painted objects and add them to the scheduler again
143 void Scheduler::InsertEvent(Event
& rNew
)
145 // insert maintaining time ordering
146 auto it
= std::find_if(mvEvents
.begin(), mvEvents
.end(),
147 [&rNew
](const Event
* pEvent
) { return rNew
.GetTime() < pEvent
->GetTime(); });
148 mvEvents
.insert(it
, &rNew
);
152 void Scheduler::RemoveEvent(Event
* pOld
)
154 if(!mvEvents
.empty())
156 mvEvents
.erase(std::remove(mvEvents
.begin(), mvEvents
.end(), pOld
), mvEvents
.end());
161 void Scheduler::SetPaused(bool bNew
)
163 if(bNew
!= mbIsPaused
)
170 } // end of namespace
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */