LibreOffice Module svx (master)  1
animationstate.cxx
Go to the documentation of this file.
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 
26 #include <comphelper/lok.hxx>
27 
28 
29 namespace sdr::animation
30 {
31  double PrimitiveAnimation::getSmallestNextTime(double fCurrentTime)
32  {
33  double fRetval(0.0);
34 
35  if(!maAnimatedPrimitives.empty())
36  {
37  const sal_Int32 nCount(maAnimatedPrimitives.size());
38 
39  for(sal_Int32 a(0); a < nCount; a++)
40  {
43  OSL_ENSURE(pCandidate, "PrimitiveAnimation::getSmallestNextTime: wrong primitive in animated list (!)");
44 
45  if(pCandidate)
46  {
47  const drawinglayer::animation::AnimationEntry& rAnimEntry = pCandidate->getAnimationEntry();
48  const double fNextTime(rAnimEntry.getNextEventTime(fCurrentTime));
49 
50  if(!::basegfx::fTools::equalZero(fNextTime))
51  {
52  if(::basegfx::fTools::equalZero(fRetval))
53  {
54  fRetval = fNextTime;
55  }
56  else if(::basegfx::fTools::less(fNextTime, fRetval))
57  {
58  fRetval = fNextTime;
59  }
60  }
61  }
62  }
63  }
64 
65  return fRetval;
66  }
67 
69  {
70  const double fCurrentTime(mrVOContact.GetObjectContact().getPrimitiveAnimator().GetTime());
71  const double fNextTime(getSmallestNextTime(fCurrentTime));
72 
73  // getSmallestNextTime will be zero when animation ended. If not zero, a next step
74  // exists
75  if(::basegfx::fTools::equalZero(fNextTime))
76  return;
77 
78  // next time point exists, use it
79  sal_uInt32 nNextTime;
80 
81  if(fNextTime >= double(0xffffff00))
82  {
83  // take care for very late points in time, e.g. when a text animation stops
84  // in a defined AnimationEntryFixed with endless (0xffffffff) duration
85  nNextTime = GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much...
86  }
87  else
88  {
89  nNextTime = static_cast<sal_uInt32>(fNextTime);
90  }
91 
92  // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use
93  // at least 25ms for next step
94  const sal_uInt32 nMinimumStepTime(static_cast<sal_uInt32>(fCurrentTime) + 25);
95 
96  if(nNextTime <= nMinimumStepTime)
97  {
98  nNextTime = nMinimumStepTime;
99  }
100 
101  // set time and reactivate by re-adding to the scheduler
102  SetTime(nNextTime);
104  }
105 
107  : Event(),
108  mrVOContact(rVOContact),
109  maAnimatedPrimitives(rAnimatedPrimitives)
110  {
112  // setup initially
114  }
115 
117  {
118  // ensure that Event member is removed from PrimitiveAnimator
120  }
121 
122  // execute event, from base class Event
123  void PrimitiveAnimation::Trigger(sal_uInt32 /*nTime*/)
124  {
125  // schedule a repaint of associated object
127 
129  // re-setup
131  }
132 
133 } // end of namespace
134 
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE void RemoveEvent(Event *pOld)
Definition: scheduler.cxx:152
void InsertEvent(Event &rNew)
Definition: scheduler.cxx:143
int nCount
sdr::animation::primitiveAnimator & getPrimitiveAnimator()
static bool less(const double &rfValA, const double &rfValB)
ObjectContact & GetObjectContact() const
uno_Any a
virtual void Trigger(sal_uInt32 nTime) override
void SetTime(sal_uInt32 nNew)
Definition: scheduler.cxx:39
static bool equalZero(const double &rfVal)
SAL_DLLPRIVATE sal_uInt32 GetTime() const
Definition: scheduler.hxx:74
const animation::AnimationEntry & getAnimationEntry() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
SAL_DLLPRIVATE sal_uInt32 GetTime() const
Definition: scheduler.hxx:43
drawinglayer::primitive2d::Primitive2DContainer maAnimatedPrimitives
virtual double getNextEventTime(double fTime) const =0
sdr::contact::ViewObjectContact & mrVOContact
PrimitiveAnimation(sdr::contact::ViewObjectContact &rVOContact, const drawinglayer::primitive2d::Primitive2DContainer &rAnimatedPrimitives)
double getSmallestNextTime(double fCurrentTime)