Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / transitions / randomwipe.cxx
blob584c17b1c0f16f142be3ede7faa7ee9e18ea4773
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 .
21 #include <basegfx/matrix/b2dhommatrix.hxx>
22 #include <basegfx/numeric/ftools.hxx>
23 #include <basegfx/matrix/b2dhommatrixtools.hxx>
24 #include "randomwipe.hxx"
25 #include <tools.hxx>
28 namespace slideshow {
29 namespace internal {
31 RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
32 : m_positions( new ::basegfx::B2DPoint[ nElements ] ),
33 m_nElements( nElements ),
34 m_rect( createUnitRect() )
36 ::basegfx::B2DHomMatrix aTransform;
37 if (randomBars)
39 double edge = (1.0 / nElements);
40 for ( sal_Int32 pos = nElements; pos--; )
41 m_positions[ pos ].setY( ::basegfx::pruneScaleValue( pos * edge ) );
42 aTransform.scale( 1.0, ::basegfx::pruneScaleValue(edge) );
44 else // dissolve effect
46 sal_Int32 sqrtElements = static_cast<sal_Int32>(
47 sqrt( static_cast<double>(nElements) ) );
48 double edge = (1.0 / sqrtElements);
49 for ( sal_Int32 pos = nElements; pos--; ) {
50 m_positions[ pos ] = ::basegfx::B2DPoint(
51 ::basegfx::pruneScaleValue( (pos % sqrtElements) * edge ),
52 ::basegfx::pruneScaleValue( (pos / sqrtElements) * edge ) );
54 const double pedge = ::basegfx::pruneScaleValue(edge);
55 aTransform.scale( pedge, pedge );
57 m_rect.transform( aTransform );
59 // mix up:
60 for ( sal_Int32 pos1 = nElements ; pos1-- ; )
62 const sal_Int32 pos2 = getRandomOrdinal(pos1+1);
63 ::std::swap(m_positions[ pos1], m_positions[ pos2 ]);
67 ::basegfx::B2DPolyPolygon RandomWipe::operator () ( double t )
69 ::basegfx::B2DPolyPolygon res;
70 for ( sal_Int32 pos = static_cast<sal_Int32>(t * m_nElements); pos--; )
72 ::basegfx::B2DPoint const & point = m_positions[ pos ];
73 ::basegfx::B2DPolygon poly( m_rect );
74 poly.transform(basegfx::utils::createTranslateB2DHomMatrix(point.getX(), point.getY()));
75 res.append( poly );
77 return res;
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */