Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / transitions / spiralwipe.cxx
blob216c513ff4704a378714436e4b20c26c03f3912e
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 "spiralwipe.hxx"
22 #include "transitiontools.hxx"
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <basegfx/numeric/ftools.hxx>
27 #include <basegfx/matrix/b2dhommatrixtools.hxx>
30 namespace slideshow {
31 namespace internal {
33 SpiralWipe::SpiralWipe( sal_Int32 nElements, bool flipOnYAxis )
34 : m_elements(nElements),
35 m_sqrtElements( static_cast<sal_Int32>(
36 sqrt( static_cast<double>(nElements) ) ) ),
37 m_flipOnYAxis(flipOnYAxis)
41 ::basegfx::B2DPolyPolygon SpiralWipe::calcNegSpiral( double t ) const
43 const double area = (t * m_elements);
44 const double e = (sqrt(area) / 2.0);
45 const sal_Int32 edge = (static_cast<sal_Int32>(e) * 2);
47 basegfx::B2DHomMatrix aTransform(basegfx::utils::createTranslateB2DHomMatrix(-0.5, -0.5));
48 const double edge_ = ::basegfx::pruneScaleValue(
49 static_cast<double>(edge) / m_sqrtElements );
50 aTransform.scale( edge_, edge_ );
51 aTransform.translate( 0.5, 0.5 );
52 ::basegfx::B2DPolygon poly( createUnitRect() );
53 poly.transform( aTransform );
54 ::basegfx::B2DPolyPolygon res(poly);
56 if (! ::basegfx::fTools::equalZero( 1.0 - t )) {
57 const sal_Int32 edge1 = (edge + 1);
58 sal_Int32 len = static_cast<sal_Int32>( (e - (edge /2)) * edge1 * 4 );
59 double w = M_PI_2;
60 while (len > 0) {
61 const sal_Int32 alen = (len > edge1 ? edge1 : len);
62 len -= alen;
63 poly = createUnitRect();
64 aTransform = basegfx::utils::createScaleB2DHomMatrix(
65 ::basegfx::pruneScaleValue( static_cast<double>(alen) / m_sqrtElements ),
66 ::basegfx::pruneScaleValue( 1.0 / m_sqrtElements ) );
67 aTransform.translate(
68 - ::basegfx::pruneScaleValue(
69 static_cast<double>(edge / 2) / m_sqrtElements ),
70 ::basegfx::pruneScaleValue(
71 static_cast<double>(edge / 2) / m_sqrtElements ) );
72 aTransform.rotate( w );
73 w -= M_PI_2;
74 aTransform.translate( 0.5, 0.5 );
75 poly.transform( aTransform );
76 res.append(poly);
80 return res;
83 ::basegfx::B2DPolyPolygon SpiralWipe::operator () ( double t )
85 ::basegfx::B2DPolyPolygon res( createUnitRect() );
86 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
87 innerSpiral.flip();
88 res.append(innerSpiral);
89 return m_flipOnYAxis ? flipOnYAxis(res) : res;
92 ::basegfx::B2DPolyPolygon BoxSnakesWipe::operator () ( double t )
94 ::basegfx::B2DPolyPolygon res( createUnitRect() );
95 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
96 innerSpiral.flip();
98 if (m_fourBox) {
99 ::basegfx::B2DHomMatrix aTransform;
100 aTransform.scale( 0.5, 0.5 );
101 innerSpiral.transform( aTransform );
102 res.append(innerSpiral);
103 res.append( flipOnXAxis(innerSpiral) );
104 innerSpiral = flipOnYAxis(innerSpiral);
105 res.append(innerSpiral);
106 res.append( flipOnXAxis(innerSpiral) );
108 else {
109 ::basegfx::B2DHomMatrix aTransform;
110 aTransform.scale( 1.0, 0.5 );
111 innerSpiral.transform( aTransform );
112 res.append(innerSpiral);
113 res.append( flipOnXAxis(innerSpiral) );
116 return m_flipOnYAxis ? flipOnYAxis(res) : res;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */