bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / engine / transitions / randomwipe.cxx
blob95ae48674696b6d22dc3b4ad6e706aae5982ece4
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 <canvas/debug.hxx>
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/numeric/ftools.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 #include "randomwipe.hxx"
26 #include "tools.hxx"
29 namespace slideshow {
30 namespace internal {
32 RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
33 : m_positions( new ::basegfx::B2DPoint[ nElements ] ),
34 m_nElements( nElements ),
35 m_rect( createUnitRect() )
37 ::basegfx::B2DHomMatrix aTransform;
38 if (randomBars)
40 double edge = (1.0 / nElements);
41 for ( sal_Int32 pos = nElements; pos--; )
42 m_positions[ pos ].setY( ::basegfx::pruneScaleValue( pos * edge ) );
43 aTransform.scale( 1.0, ::basegfx::pruneScaleValue(edge) );
45 else // dissolve effect
47 sal_Int32 sqrtElements = static_cast<sal_Int32>(
48 sqrt( static_cast<double>(nElements) ) );
49 double edge = (1.0 / sqrtElements);
50 for ( sal_Int32 pos = nElements; pos--; ) {
51 m_positions[ pos ] = ::basegfx::B2DPoint(
52 ::basegfx::pruneScaleValue( (pos % sqrtElements) * edge ),
53 ::basegfx::pruneScaleValue( (pos / sqrtElements) * edge ) );
55 const double pedge = ::basegfx::pruneScaleValue(edge);
56 aTransform.scale( pedge, pedge );
58 m_rect.transform( aTransform );
60 // mix up:
61 for ( sal_Int32 pos1 = nElements ; pos1-- ; )
63 const sal_Int32 pos2 = getRandomOrdinal(pos1+1);
64 ::std::swap(m_positions[ pos1], m_positions[ pos2 ]);
68 ::basegfx::B2DPolyPolygon RandomWipe::operator () ( double t )
70 ::basegfx::B2DPolyPolygon res;
71 for ( sal_Int32 pos = static_cast<sal_Int32>(t * m_nElements); pos--; )
73 ::basegfx::B2DPoint const & point = m_positions[ pos ];
74 ::basegfx::B2DPolygon poly( m_rect );
75 poly.transform(basegfx::tools::createTranslateB2DHomMatrix(point.getX(), point.getY()));
76 res.append( poly );
78 return res;
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */