/src/libreoffice/svx/source/sdr/animation/animationstate.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <svx/sdr/animation/animationstate.hxx> |
21 | | #include <svx/sdr/contact/viewobjectcontact.hxx> |
22 | | #include <svx/sdr/animation/objectanimator.hxx> |
23 | | #include <svx/sdr/contact/objectcontact.hxx> |
24 | | #include <drawinglayer/primitive2d/animatedprimitive2d.hxx> |
25 | | #include <drawinglayer/animation/animationtiming.hxx> |
26 | | #include <comphelper/lok.hxx> |
27 | | |
28 | | |
29 | | namespace sdr::animation |
30 | | { |
31 | | double PrimitiveAnimation::getSmallestNextTime(double fCurrentTime) |
32 | 0 | { |
33 | 0 | double fRetval(0.0); |
34 | |
|
35 | 0 | if(!maAnimatedPrimitives.empty()) |
36 | 0 | { |
37 | 0 | for(const drawinglayer::primitive2d::Primitive2DReference & xRef : maAnimatedPrimitives) |
38 | 0 | { |
39 | 0 | const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* pCandidate = static_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* >(xRef.get()); |
40 | |
|
41 | 0 | const drawinglayer::animation::AnimationEntry& rAnimEntry = pCandidate->getAnimationEntry(); |
42 | 0 | const double fNextTime(rAnimEntry.getNextEventTime(fCurrentTime)); |
43 | |
|
44 | 0 | if(!::basegfx::fTools::equalZero(fNextTime)) |
45 | 0 | { |
46 | 0 | if(::basegfx::fTools::equalZero(fRetval)) |
47 | 0 | { |
48 | 0 | fRetval = fNextTime; |
49 | 0 | } |
50 | 0 | else if(::basegfx::fTools::less(fNextTime, fRetval)) |
51 | 0 | { |
52 | 0 | fRetval = fNextTime; |
53 | 0 | } |
54 | 0 | } |
55 | 0 | } |
56 | 0 | } |
57 | |
|
58 | 0 | return fRetval; |
59 | 0 | } |
60 | | |
61 | | void PrimitiveAnimation::prepareNextEvent() |
62 | 0 | { |
63 | 0 | const double fCurrentTime(mrVOContact.GetObjectContact().getPrimitiveAnimator().GetTime()); |
64 | 0 | const double fNextTime(getSmallestNextTime(fCurrentTime)); |
65 | | |
66 | | // getSmallestNextTime will be zero when animation ended. If not zero, a next step |
67 | | // exists |
68 | 0 | if(::basegfx::fTools::equalZero(fNextTime)) |
69 | 0 | return; |
70 | | |
71 | | // next time point exists, use it |
72 | 0 | sal_uInt32 nNextTime; |
73 | |
|
74 | 0 | if(fNextTime >= double(0xffffff00)) |
75 | 0 | { |
76 | | // take care for very late points in time, e.g. when a text animation stops |
77 | | // in a defined AnimationEntryFixed with endless (0xffffffff) duration |
78 | 0 | nNextTime = GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much... |
79 | 0 | } |
80 | 0 | else |
81 | 0 | { |
82 | 0 | nNextTime = static_cast<sal_uInt32>(fNextTime); |
83 | 0 | } |
84 | | |
85 | | // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use |
86 | | // at least 25ms for next step |
87 | 0 | const sal_uInt32 nMinimumStepTime(static_cast<sal_uInt32>(fCurrentTime) + 25); |
88 | |
|
89 | 0 | if(nNextTime <= nMinimumStepTime) |
90 | 0 | { |
91 | 0 | nNextTime = nMinimumStepTime; |
92 | 0 | } |
93 | | |
94 | | // set time and reactivate by re-adding to the scheduler |
95 | 0 | SetTime(nNextTime); |
96 | 0 | mrVOContact.GetObjectContact().getPrimitiveAnimator().InsertEvent(*this); |
97 | 0 | } |
98 | | |
99 | | PrimitiveAnimation::PrimitiveAnimation(sdr::contact::ViewObjectContact& rVOContact, drawinglayer::primitive2d::Primitive2DContainer&& rAnimatedPrimitives) |
100 | 0 | : mrVOContact(rVOContact), |
101 | 0 | maAnimatedPrimitives(std::move(rAnimatedPrimitives)) |
102 | 0 | { |
103 | 0 | if (!comphelper::LibreOfficeKit::isActive()) |
104 | | // setup initially |
105 | 0 | prepareNextEvent(); |
106 | 0 | } |
107 | | |
108 | | PrimitiveAnimation::~PrimitiveAnimation() |
109 | 0 | { |
110 | | // ensure that Event member is removed from PrimitiveAnimator |
111 | 0 | mrVOContact.GetObjectContact().getPrimitiveAnimator().RemoveEvent(this); |
112 | 0 | } |
113 | | |
114 | | // execute event, from base class Event |
115 | | void PrimitiveAnimation::Trigger(sal_uInt32 /*nTime*/) |
116 | 0 | { |
117 | | // schedule a repaint of associated object |
118 | 0 | mrVOContact.ActionChanged(); |
119 | |
|
120 | 0 | if (!comphelper::LibreOfficeKit::isActive()) |
121 | | // re-setup |
122 | 0 | prepareNextEvent(); |
123 | 0 | } |
124 | | |
125 | | } // end of namespace |
126 | | |
127 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |