fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / activities / interpolation.hxx
blob6effd085e0a3e3fc8629fc8de9c4d8ad711d918a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_ACTIVITIES_INTERPOLATION_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_ACTIVITIES_INTERPOLATION_HXX
23 #include <basegfx/tools/lerp.hxx>
25 namespace basegfx
27 namespace tools
29 // Interpolator specializations
30 // ============================
32 // NOTE: generic lerp is included from lerp.hxx. Following
33 // are some specializations for various
34 // not-straight-forward-interpolatable types
36 /// Specialization for RGBColor, to employ color-specific interpolator
37 template<> ::slideshow::internal::RGBColor lerp< ::slideshow::internal::RGBColor >(
38 const ::slideshow::internal::RGBColor& rFrom,
39 const ::slideshow::internal::RGBColor& rTo,
40 double t )
42 return interpolate( rFrom, rTo, t );
45 /// Specialization also for sal_Int16, although this code should not be called
46 template<> sal_Int16 lerp< sal_Int16 >( const sal_Int16&,
47 const sal_Int16& rTo,
48 double )
50 OSL_FAIL( "lerp<sal_Int16> called" );
51 return rTo;
54 /// Specialization also for string, although this code should not be called
55 template<> OUString lerp< OUString >( const OUString&,
56 const OUString& rTo,
57 double )
59 OSL_FAIL( "lerp<OUString> called" );
60 return rTo;
63 /// Specialization also for bool, although this code should not be called
64 template<> bool lerp< bool >( const bool&,
65 const bool& rTo,
66 double )
68 OSL_FAIL( "lerp<bool> called" );
69 return rTo;
74 namespace slideshow
76 namespace internal
78 template< typename ValueType > struct Interpolator
80 ValueType operator()( const ValueType& rFrom,
81 const ValueType& rTo,
82 double t ) const
84 return basegfx::tools::lerp( rFrom, rTo, t );
88 /// Specialization for HSLColor, to employ color-specific interpolator
89 template<> struct Interpolator< HSLColor >
91 Interpolator( bool bCCW ) :
92 mbCCW( bCCW )
96 HSLColor operator()( const HSLColor& rFrom,
97 const HSLColor& rTo,
98 double t ) const
100 return interpolate( rFrom, rTo, t, mbCCW );
103 private:
104 /// When true: interpolate counter-clockwise
105 const bool mbCCW;
109 /** Generic linear interpolator
111 @tpl ValueType
112 Must have operator+ and operator* defined, and should
113 have value semantics.
115 @param rInterpolator
116 Interpolator to use for lerp
118 @param nFrame
119 Must be in the [0,nTotalFrames) range
121 @param nTotalFrames
122 Total number of frames. Should be greater than zero.
124 template< typename ValueType > ValueType lerp( const Interpolator< ValueType >& rInterpolator,
125 const ValueType& rFrom,
126 const ValueType& rTo,
127 sal_uInt32 nFrame,
128 ::std::size_t nTotalFrames )
130 // TODO(P1): There's a nice HAKMEM trick for that
131 // nTotalFrames > 1 condition below
133 // for 1 and 0 frame animations, always take end value
134 const double nFraction( nTotalFrames > 1 ? double(nFrame)/(nTotalFrames-1) : 1.0 );
136 return rInterpolator( rFrom, rTo, nFraction );
139 /// Specialization for non-interpolatable constants/enums
140 template<> sal_Int16 lerp< sal_Int16 >( const Interpolator< sal_Int16 >& /*rInterpolator*/,
141 const sal_Int16& rFrom,
142 const sal_Int16& rTo,
143 sal_uInt32 nFrame,
144 ::std::size_t nTotalFrames )
146 // until one half of the total frames are over, take from value.
147 // after that, take to value.
148 // For nFrames not divisable by 2, we prefer to over from, which
149 // also neatly yields to for 1 frame activities
150 return nFrame < nTotalFrames/2 ? rFrom : rTo;
153 /// Specialization for non-interpolatable strings
154 template<> OUString lerp< OUString >( const Interpolator< OUString >& /*rInterpolator*/,
155 const OUString& rFrom,
156 const OUString& rTo,
157 sal_uInt32 nFrame,
158 ::std::size_t nTotalFrames )
160 // until one half of the total frames are over, take from value.
161 // after that, take to value.
162 // For nFrames not divisable by 2, we prefer to over from, which
163 // also neatly yields to for 1 frame activities
164 return nFrame < nTotalFrames/2 ? rFrom : rTo;
167 /// Specialization for non-interpolatable bools
168 template<> bool lerp< bool >( const Interpolator< bool >& /*rInterpolator*/,
169 const bool& bFrom,
170 const bool& bTo,
171 sal_uInt32 nFrame,
172 ::std::size_t nTotalFrames )
174 // until one half of the total frames are over, take from value.
175 // after that, take to value.
176 // For nFrames not divisable by 2, we prefer to over from, which
177 // also neatly yields to for 1 frame activities
178 return nFrame < nTotalFrames/2 ? bFrom : bTo;
183 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_ACTIVITIES_INTERPOLATION_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */