1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*70f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*70f497fbSAndrew Rist  * distributed with this work for additional information
6*70f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*70f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*70f497fbSAndrew Rist  *
11*70f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist  *
13*70f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist  * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
17*70f497fbSAndrew Rist  * specific language governing permissions and limitations
18*70f497fbSAndrew Rist  * under the License.
19*70f497fbSAndrew Rist  *
20*70f497fbSAndrew Rist  *************************************************************/
21*70f497fbSAndrew Rist 
22*70f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include "spiralwipe.hxx"
29cdf0e10cSrcweir #include "transitiontools.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
33cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
34cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace slideshow {
38cdf0e10cSrcweir namespace internal {
39cdf0e10cSrcweir 
SpiralWipe(sal_Int32 nElements,bool flipOnYAxis)40cdf0e10cSrcweir SpiralWipe::SpiralWipe( sal_Int32 nElements, bool flipOnYAxis )
41cdf0e10cSrcweir     : m_elements(nElements),
42cdf0e10cSrcweir       m_sqrtElements( static_cast<sal_Int32>(
43cdf0e10cSrcweir                           sqrt( static_cast<double>(nElements) ) ) ),
44cdf0e10cSrcweir       m_flipOnYAxis(flipOnYAxis)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
calcNegSpiral(double t) const48cdf0e10cSrcweir ::basegfx::B2DPolyPolygon SpiralWipe::calcNegSpiral( double t ) const
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     const double area = (t * m_elements);
51cdf0e10cSrcweir     const double e = (sqrt(area) / 2.0);
52cdf0e10cSrcweir     const sal_Int32 edge = (static_cast<sal_Int32>(e) * 2);
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     basegfx::B2DHomMatrix aTransform(basegfx::tools::createTranslateB2DHomMatrix(-0.5, -0.5));
55cdf0e10cSrcweir     const double edge_ = ::basegfx::pruneScaleValue(
56cdf0e10cSrcweir         static_cast<double>(edge) / m_sqrtElements );
57cdf0e10cSrcweir     aTransform.scale( edge_, edge_ );
58cdf0e10cSrcweir     aTransform.translate( 0.5, 0.5 );
59cdf0e10cSrcweir     ::basegfx::B2DPolygon poly( createUnitRect() );
60cdf0e10cSrcweir     poly.transform( aTransform );
61cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon res(poly);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     if (! ::basegfx::fTools::equalZero( 1.0 - t )) {
64cdf0e10cSrcweir         const sal_Int32 edge1 = (edge + 1);
65cdf0e10cSrcweir         sal_Int32 len = static_cast<sal_Int32>( (e - (edge /2)) * edge1 * 4 );
66cdf0e10cSrcweir         double w = M_PI_2;
67cdf0e10cSrcweir         while (len > 0) {
68cdf0e10cSrcweir             const sal_Int32 alen = (len > edge1 ? edge1 : len);
69cdf0e10cSrcweir             len -= alen;
70cdf0e10cSrcweir             poly = createUnitRect();
71cdf0e10cSrcweir             aTransform = basegfx::tools::createScaleB2DHomMatrix(
72cdf0e10cSrcweir                 ::basegfx::pruneScaleValue( static_cast<double>(alen) / m_sqrtElements ),
73cdf0e10cSrcweir                 ::basegfx::pruneScaleValue( 1.0 / m_sqrtElements ) );
74cdf0e10cSrcweir             aTransform.translate(
75cdf0e10cSrcweir                 - ::basegfx::pruneScaleValue(
76cdf0e10cSrcweir                     static_cast<double>(edge / 2) / m_sqrtElements ),
77cdf0e10cSrcweir                 ::basegfx::pruneScaleValue(
78cdf0e10cSrcweir                     static_cast<double>(edge / 2) / m_sqrtElements ) );
79cdf0e10cSrcweir             aTransform.rotate( w );
80cdf0e10cSrcweir             w -= M_PI_2;
81cdf0e10cSrcweir             aTransform.translate( 0.5, 0.5 );
82cdf0e10cSrcweir             poly.transform( aTransform );
83cdf0e10cSrcweir             res.append(poly);
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     return res;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
operator ()(double t)90cdf0e10cSrcweir ::basegfx::B2DPolyPolygon SpiralWipe::operator () ( double t )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon res( createUnitRect() );
93cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
94cdf0e10cSrcweir     innerSpiral.flip();
95cdf0e10cSrcweir     res.append(innerSpiral);
96cdf0e10cSrcweir     return m_flipOnYAxis ? flipOnYAxis(res) : res;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
operator ()(double t)99cdf0e10cSrcweir ::basegfx::B2DPolyPolygon BoxSnakesWipe::operator () ( double t )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon res( createUnitRect() );
102cdf0e10cSrcweir     ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
103cdf0e10cSrcweir     innerSpiral.flip();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     if (m_fourBox) {
106cdf0e10cSrcweir         ::basegfx::B2DHomMatrix aTransform;
107cdf0e10cSrcweir         aTransform.scale( 0.5, 0.5 );
108cdf0e10cSrcweir         innerSpiral.transform( aTransform );
109cdf0e10cSrcweir         res.append(innerSpiral);
110cdf0e10cSrcweir         res.append( flipOnXAxis(innerSpiral) );
111cdf0e10cSrcweir         innerSpiral = flipOnYAxis(innerSpiral);
112cdf0e10cSrcweir         res.append(innerSpiral);
113cdf0e10cSrcweir         res.append( flipOnXAxis(innerSpiral) );
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir     else {
116cdf0e10cSrcweir         ::basegfx::B2DHomMatrix aTransform;
117cdf0e10cSrcweir         aTransform.scale( 1.0, 0.5 );
118cdf0e10cSrcweir         innerSpiral.transform( aTransform );
119cdf0e10cSrcweir         res.append(innerSpiral);
120cdf0e10cSrcweir         res.append( flipOnXAxis(innerSpiral) );
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     return m_flipOnYAxis ? flipOnYAxis(res) : res;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128