LibreOffice Module slideshow (master) 1
randomwipe.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
24#include "randomwipe.hxx"
25#include "transitiontools.hxx"
26#include <tools.hxx>
27
28
29namespace slideshow::internal {
30
31RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
32 : m_positions( new ::basegfx::B2DPoint[ nElements ] ),
33 m_nElements( nElements ),
34 m_rect( createUnitRect() )
35{
36 ::basegfx::B2DHomMatrix aTransform;
37 if (randomBars)
38 {
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) );
43 }
44 else // dissolve effect
45 {
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--; ) {
51 ::basegfx::pruneScaleValue( (pos % sqrtElements) * edge ),
52 ::basegfx::pruneScaleValue( (pos / sqrtElements) * edge ) );
53 }
54 const double pedge = ::basegfx::pruneScaleValue(edge);
55 aTransform.scale( pedge, pedge );
56 }
57 m_rect.transform( aTransform );
58
59 // mix up:
60 for ( sal_Int32 pos1 = nElements ; pos1-- ; )
61 {
62 const sal_Int32 pos2 = getRandomOrdinal(pos1+1);
63 ::std::swap(m_positions[ pos1], m_positions[ pos2 ]);
64 }
65}
66
68{
70 for ( sal_Int32 pos = static_cast<sal_Int32>(t * m_nElements); pos--; )
71 {
75 res.append( poly );
76 }
77 return res;
78}
79
80}
81
82/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
void scale(double fX, double fY)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void transform(const basegfx::B2DHomMatrix &rMatrix)
RandomWipe(sal_Int32 nElements, bool randomBars)
Definition: randomwipe.cxx:31
::std::unique_ptr<::basegfx::B2DPoint[]> m_positions
Definition: randomwipe.hxx:39
virtual ::basegfx::B2DPolyPolygon operator()(double t) override
Retrieve the poly-polygon for value t.
Definition: randomwipe.cxx:67
::basegfx::B2DPolygon m_rect
Definition: randomwipe.hxx:41
sal_Int32 nElements
def point()
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
inline ::std::size_t getRandomOrdinal(const ::std::size_t n)
Gets a random ordinal [0,n)
Definition: tools.hxx:272
::basegfx::B2DPolygon createUnitRect()
Create a unit rect.
size_t pos