xref: /AOO41X/main/sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx (revision 5b1900111deff329a5580f97b99b67a25168e53d)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir #include "controller/SlsAnimationFunction.hxx"
26cdf0e10cSrcweir #include "model/SlsPageDescriptor.hxx"
27cdf0e10cSrcweir #include "view/SlideSorterView.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <osl/diagnose.hxx>
31cdf0e10cSrcweir #include <rtl/math.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace controller {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
Linear(const double nTime)36cdf0e10cSrcweir double AnimationFunction::Linear (const double nTime)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     OSL_ASSERT(nTime>=0.0 && nTime<=1.0);
39cdf0e10cSrcweir     return nTime;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
FastInSlowOut_Sine(const double nTime)45cdf0e10cSrcweir double AnimationFunction::FastInSlowOut_Sine (const double nTime)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     OSL_ASSERT(nTime>=0.0 && nTime<=1.0);
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     const double nResult (sin(nTime * M_PI/2));
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     OSL_ASSERT(nResult>=0.0 && nResult<=1.0);
52cdf0e10cSrcweir     return nResult;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
FastInSlowOut_Root(const double nTime)58cdf0e10cSrcweir double AnimationFunction::FastInSlowOut_Root (const double nTime)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     OSL_ASSERT(nTime>=0.0 && nTime<=1.0);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     const double nResult (sqrt(nTime));
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     OSL_ASSERT(nResult>=0.0 && nResult<=1.0);
65cdf0e10cSrcweir     return nResult;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
SlowInSlowOut_0to0_Sine(const double nTime)71cdf0e10cSrcweir double AnimationFunction::SlowInSlowOut_0to0_Sine (const double nTime)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     OSL_ASSERT(nTime>=0.0 && nTime<=1.0);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     const double nResult (sin(nTime * M_PI));
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     OSL_ASSERT(nResult>=0.0 && nResult<=1.0);
78cdf0e10cSrcweir     return nResult;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
Vibrate_Sine(const double nTime)84cdf0e10cSrcweir double AnimationFunction::Vibrate_Sine (const double nTime)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     return sin(nTime*M_PI*8);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
ScalePoint(const Point & rPoint,const double nTime)92cdf0e10cSrcweir Point AnimationFunction::ScalePoint (const Point& rPoint, const double nTime)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     return Point(
95cdf0e10cSrcweir         sal_Int32(::rtl::math::round(rPoint.X() * nTime)),
96cdf0e10cSrcweir         sal_Int32(::rtl::math::round(rPoint.Y() * nTime)));
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
Blend(const double nStartValue,const double nEndValue,const double nTime)102cdf0e10cSrcweir double AnimationFunction::Blend (
103cdf0e10cSrcweir     const double nStartValue,
104cdf0e10cSrcweir     const double nEndValue,
105cdf0e10cSrcweir     const double nTime)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     return nStartValue*(1-nTime) + nEndValue*nTime;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
ApplyVisualStateChange(const model::SharedPageDescriptor & rpDescriptor,view::SlideSorterView & rView,const double nTime)113cdf0e10cSrcweir void AnimationFunction::ApplyVisualStateChange (
114cdf0e10cSrcweir     const model::SharedPageDescriptor& rpDescriptor,
115cdf0e10cSrcweir     view::SlideSorterView& rView,
116cdf0e10cSrcweir     const double nTime)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     if (rpDescriptor)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         rpDescriptor->GetVisualState().SetVisualStateBlend(nTime);
121cdf0e10cSrcweir         rView.RequestRepaint(rpDescriptor);
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
ApplyLocationOffsetChange(const model::SharedPageDescriptor & rpDescriptor,view::SlideSorterView & rView,const Point aLocationOffset)128cdf0e10cSrcweir void AnimationFunction::ApplyLocationOffsetChange (
129cdf0e10cSrcweir     const model::SharedPageDescriptor& rpDescriptor,
130cdf0e10cSrcweir     view::SlideSorterView& rView,
131cdf0e10cSrcweir     const Point aLocationOffset)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     if (rpDescriptor)
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         const Rectangle aOldBoundingBox(rpDescriptor->GetBoundingBox());
136cdf0e10cSrcweir         rpDescriptor->GetVisualState().SetLocationOffset(aLocationOffset);
137cdf0e10cSrcweir         rView.RequestRepaint(aOldBoundingBox);
138cdf0e10cSrcweir         rView.RequestRepaint(rpDescriptor);
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
ApplyButtonAlphaChange(const model::SharedPageDescriptor & rpDescriptor,view::SlideSorterView & rView,const double nButtonAlpha,const double nButtonBarAlpha)145cdf0e10cSrcweir void AnimationFunction::ApplyButtonAlphaChange(
146cdf0e10cSrcweir     const model::SharedPageDescriptor& rpDescriptor,
147cdf0e10cSrcweir     view::SlideSorterView& rView,
148cdf0e10cSrcweir     const double nButtonAlpha,
149cdf0e10cSrcweir     const double nButtonBarAlpha)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     if (rpDescriptor)
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         rpDescriptor->GetVisualState().SetButtonAlpha(nButtonAlpha);
154cdf0e10cSrcweir         rpDescriptor->GetVisualState().SetButtonBarAlpha(nButtonBarAlpha);
155cdf0e10cSrcweir         rView.RequestRepaint(rpDescriptor);
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //===== AnimationBezierFunction ===============================================
163cdf0e10cSrcweir 
AnimationBezierFunction(const double nX1,const double nY1,const double nX2,const double nY2)164cdf0e10cSrcweir AnimationBezierFunction::AnimationBezierFunction (
165cdf0e10cSrcweir     const double nX1,
166cdf0e10cSrcweir     const double nY1,
167cdf0e10cSrcweir     const double nX2,
168cdf0e10cSrcweir     const double nY2)
169cdf0e10cSrcweir     : mnX1(nX1),
170cdf0e10cSrcweir       mnY1(nY1),
171cdf0e10cSrcweir       mnX2(nX2),
172cdf0e10cSrcweir       mnY2(nY2)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
AnimationBezierFunction(const double nX1,const double nY1)179cdf0e10cSrcweir AnimationBezierFunction::AnimationBezierFunction (
180cdf0e10cSrcweir     const double nX1,
181cdf0e10cSrcweir     const double nY1)
182cdf0e10cSrcweir     : mnX1(nX1),
183cdf0e10cSrcweir       mnY1(nY1),
184cdf0e10cSrcweir       mnX2(1-nY1),
185cdf0e10cSrcweir       mnY2(1-nX1)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
operator ()(const double nT)192cdf0e10cSrcweir ::basegfx::B2DPoint AnimationBezierFunction::operator() (const double nT)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     return ::basegfx::B2DPoint(
195cdf0e10cSrcweir         EvaluateComponent(nT, mnX1, mnX2),
196cdf0e10cSrcweir         EvaluateComponent(nT, mnY1, mnY2));
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
EvaluateComponent(const double nT,const double nV1,const double nV2)202cdf0e10cSrcweir double AnimationBezierFunction::EvaluateComponent (
203cdf0e10cSrcweir     const double nT,
204cdf0e10cSrcweir     const double nV1,
205cdf0e10cSrcweir     const double nV2)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     const double nS (1-nT);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     // While the control point values 1 and 2 are explicitly given the start
210cdf0e10cSrcweir     // and end values are implicitly given.
211cdf0e10cSrcweir     const double nV0 (0);
212cdf0e10cSrcweir     const double nV3 (1);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     const double nV01 (nS*nV0 + nT*nV1);
215cdf0e10cSrcweir     const double nV12 (nS*nV1 + nT*nV2);
216cdf0e10cSrcweir     const double nV23 (nS*nV2 + nT*nV3);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     const double nV012 (nS*nV01 + nT*nV12);
219cdf0e10cSrcweir     const double nV123 (nS*nV12 + nT*nV23);
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     const double nV0123 (nS*nV012 + nT*nV123);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     return nV0123;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
229cdf0e10cSrcweir //===== AnimationParametricFunction ===========================================
230cdf0e10cSrcweir 
AnimationParametricFunction(const ParametricFunction & rFunction)231cdf0e10cSrcweir AnimationParametricFunction::AnimationParametricFunction (const ParametricFunction& rFunction)
232cdf0e10cSrcweir     : maY()
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     const sal_Int32 nSampleCount (64);
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     // Sample the given parametric function.
237cdf0e10cSrcweir     ::std::vector<basegfx::B2DPoint> aPoints;
238cdf0e10cSrcweir     aPoints.reserve(nSampleCount);
239cdf0e10cSrcweir     for (sal_Int32 nIndex=0; nIndex<nSampleCount; ++nIndex)
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         const double nT (nIndex/double(nSampleCount-1));
242cdf0e10cSrcweir         aPoints.push_back(basegfx::B2DPoint(rFunction(nT)));
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     // Interpolate at evenly spaced points.
246cdf0e10cSrcweir     maY.clear();
247cdf0e10cSrcweir     maY.reserve(nSampleCount);
248cdf0e10cSrcweir     double nX0 (aPoints[0].getX());
249cdf0e10cSrcweir     double nY0 (aPoints[0].getY());
250cdf0e10cSrcweir     double nX1 (aPoints[1].getX());
251cdf0e10cSrcweir     double nY1 (aPoints[1].getY());
252cdf0e10cSrcweir     sal_Int32 nIndex (1);
253cdf0e10cSrcweir     for (sal_Int32 nIndex2=0; nIndex2<nSampleCount; ++nIndex2)
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         const double nX (nIndex2 / double(nSampleCount-1));
256cdf0e10cSrcweir         while (nX > nX1 && nIndex<nSampleCount)
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             nX0 = nX1;
259cdf0e10cSrcweir             nY0 = nY1;
260cdf0e10cSrcweir             nX1 = aPoints[nIndex].getX();
261cdf0e10cSrcweir             nY1 = aPoints[nIndex].getY();
262cdf0e10cSrcweir             ++nIndex;
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir         const double nU ((nX-nX1) / (nX0 - nX1));
265cdf0e10cSrcweir         const double nY (nY0*nU + nY1*(1-nU));
266cdf0e10cSrcweir         maY.push_back(nY);
267cdf0e10cSrcweir     }
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
operator ()(const double nX)273cdf0e10cSrcweir double AnimationParametricFunction::operator() (const double nX)
274cdf0e10cSrcweir {
275117a7820SMichael Stahl     const sal_Int32 nIndex0 (static_cast<sal_Int32>(nX * maY.size()));
276cdf0e10cSrcweir     const double nX0 (nIndex0 / double(maY.size()-1));
277cdf0e10cSrcweir     const sal_uInt32 nIndex1 (nIndex0 + 1);
278cdf0e10cSrcweir     const double nX1 (nIndex1 / double(maY.size()-1));
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     if (nIndex0<=0)
281cdf0e10cSrcweir         return maY[0];
282cdf0e10cSrcweir     else if (sal_uInt32(nIndex0)>=maY.size() || nIndex1>=maY.size())
283cdf0e10cSrcweir         return maY[maY.size()-1];
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     const double nU ((nX-nX1) / (nX0 - nX1));
286cdf0e10cSrcweir     return maY[nIndex0]*nU + maY[nIndex1]*(1-nU);
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 
290cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::controller
291