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
10cdf0e10cSrcweir *
11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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 <basegfx/matrix/b2dhommatrix.hxx>
29cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
30cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
31cdf0e10cSrcweir #include "randomwipe.hxx"
32cdf0e10cSrcweir #include "tools.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir namespace slideshow {
36cdf0e10cSrcweir namespace internal {
37cdf0e10cSrcweir
RandomWipe(sal_Int32 nElements,bool randomBars)38cdf0e10cSrcweir RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
39cdf0e10cSrcweir : m_positions( new ::basegfx::B2DPoint[ nElements ] ),
40cdf0e10cSrcweir m_nElements( nElements ),
41cdf0e10cSrcweir m_rect( createUnitRect() )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTransform;
44cdf0e10cSrcweir if (randomBars)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir double edge = (1.0 / nElements);
47cdf0e10cSrcweir for ( sal_Int32 pos = nElements; pos--; )
48cdf0e10cSrcweir m_positions[ pos ].setY( ::basegfx::pruneScaleValue( pos * edge ) );
49cdf0e10cSrcweir aTransform.scale( 1.0, ::basegfx::pruneScaleValue(edge) );
50cdf0e10cSrcweir }
51cdf0e10cSrcweir else // dissolve effect
52cdf0e10cSrcweir {
53cdf0e10cSrcweir sal_Int32 sqrtElements = static_cast<sal_Int32>(
54cdf0e10cSrcweir sqrt( static_cast<double>(nElements) ) );
55cdf0e10cSrcweir double edge = (1.0 / sqrtElements);
56cdf0e10cSrcweir for ( sal_Int32 pos = nElements; pos--; ) {
57cdf0e10cSrcweir m_positions[ pos ] = ::basegfx::B2DPoint(
58cdf0e10cSrcweir ::basegfx::pruneScaleValue( (pos % sqrtElements) * edge ),
59cdf0e10cSrcweir ::basegfx::pruneScaleValue( (pos / sqrtElements) * edge ) );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir const double pedge = ::basegfx::pruneScaleValue(edge);
62cdf0e10cSrcweir aTransform.scale( pedge, pedge );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir m_rect.transform( aTransform );
65cdf0e10cSrcweir
66cdf0e10cSrcweir // mix up:
67cdf0e10cSrcweir for (sal_Int32 nIndex=0; nIndex<nElements; ++nIndex)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir const sal_Int32 nOtherIndex (getRandomOrdinal(nElements));
70cdf0e10cSrcweir OSL_ASSERT(nOtherIndex>=0 && nOtherIndex<nElements);
71cdf0e10cSrcweir ::std::swap(m_positions[nIndex], m_positions[nOtherIndex]);
72cdf0e10cSrcweir }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
operator ()(double t)75cdf0e10cSrcweir ::basegfx::B2DPolyPolygon RandomWipe::operator () ( double t )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir ::basegfx::B2DPolyPolygon res;
78cdf0e10cSrcweir for ( sal_Int32 pos = static_cast<sal_Int32>(t * m_nElements); pos--; )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir ::basegfx::B2DPoint const & point = m_positions[ pos ];
81cdf0e10cSrcweir ::basegfx::B2DPolygon poly( m_rect );
82cdf0e10cSrcweir poly.transform(basegfx::tools::createTranslateB2DHomMatrix(point.getX(), point.getY()));
83cdf0e10cSrcweir res.append( poly );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir return res;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir }
89cdf0e10cSrcweir }
90