1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_slideshow.hxx"
26 
27 #include <canvas/debug.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <basegfx/numeric/ftools.hxx>
30 #include <basegfx/matrix/b2dhommatrixtools.hxx>
31 #include "randomwipe.hxx"
32 #include "tools.hxx"
33 
34 
35 namespace slideshow {
36 namespace internal {
37 
RandomWipe(sal_Int32 nElements,bool randomBars)38 RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
39     : m_positions( new ::basegfx::B2DPoint[ nElements ] ),
40       m_nElements( nElements ),
41       m_rect( createUnitRect() )
42 {
43     ::basegfx::B2DHomMatrix aTransform;
44     if (randomBars)
45     {
46         double edge = (1.0 / nElements);
47         for ( sal_Int32 pos = nElements; pos--; )
48             m_positions[ pos ].setY( ::basegfx::pruneScaleValue( pos * edge ) );
49         aTransform.scale( 1.0, ::basegfx::pruneScaleValue(edge) );
50     }
51     else // dissolve effect
52     {
53         sal_Int32 sqrtElements = static_cast<sal_Int32>(
54             sqrt( static_cast<double>(nElements) ) );
55         double edge = (1.0 / sqrtElements);
56         for ( sal_Int32 pos = nElements; pos--; ) {
57             m_positions[ pos ] = ::basegfx::B2DPoint(
58                 ::basegfx::pruneScaleValue( (pos % sqrtElements) * edge ),
59                 ::basegfx::pruneScaleValue( (pos / sqrtElements) * edge ) );
60         }
61         const double pedge = ::basegfx::pruneScaleValue(edge);
62         aTransform.scale( pedge, pedge );
63     }
64     m_rect.transform( aTransform );
65 
66     // mix up:
67     for (sal_Int32 nIndex=0; nIndex<nElements; ++nIndex)
68     {
69         const sal_Int32 nOtherIndex (getRandomOrdinal(nElements));
70         OSL_ASSERT(nOtherIndex>=0 && nOtherIndex<nElements);
71         ::std::swap(m_positions[nIndex], m_positions[nOtherIndex]);
72     }
73 }
74 
operator ()(double t)75 ::basegfx::B2DPolyPolygon RandomWipe::operator () ( double t )
76 {
77     ::basegfx::B2DPolyPolygon res;
78     for ( sal_Int32 pos = static_cast<sal_Int32>(t * m_nElements); pos--; )
79     {
80         ::basegfx::B2DPoint const & point = m_positions[ pos ];
81         ::basegfx::B2DPolygon poly( m_rect );
82         poly.transform(basegfx::tools::createTranslateB2DHomMatrix(point.getX(), point.getY()));
83         res.append( poly );
84     }
85     return res;
86 }
87 
88 }
89 }
90