merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / transitions / spiralwipe.cxx
blob81e381abfa1ad82838cfe7683e815d61b7c8dd3b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spiralwipe.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 #include <canvas/debug.hxx>
35 #include "spiralwipe.hxx"
36 #include "transitiontools.hxx"
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <basegfx/numeric/ftools.hxx>
43 namespace slideshow {
44 namespace internal {
46 SpiralWipe::SpiralWipe( sal_Int32 nElements, bool flipOnYAxis )
47 : m_elements(nElements),
48 m_sqrtElements( static_cast<sal_Int32>(
49 sqrt( static_cast<double>(nElements) ) ) ),
50 m_flipOnYAxis(flipOnYAxis)
54 ::basegfx::B2DPolyPolygon SpiralWipe::calcNegSpiral( double t ) const
56 const double area = (t * m_elements);
57 const double e = (sqrt(area) / 2.0);
58 const sal_Int32 edge = (static_cast<sal_Int32>(e) * 2);
60 ::basegfx::B2DHomMatrix aTransform;
61 aTransform.translate( -0.5, -0.5 );
62 const double edge_ = ::basegfx::pruneScaleValue(
63 static_cast<double>(edge) / m_sqrtElements );
64 aTransform.scale( edge_, edge_ );
65 aTransform.translate( 0.5, 0.5 );
66 ::basegfx::B2DPolygon poly( createUnitRect() );
67 poly.transform( aTransform );
68 ::basegfx::B2DPolyPolygon res(poly);
70 if (! ::basegfx::fTools::equalZero( 1.0 - t )) {
71 const sal_Int32 edge1 = (edge + 1);
72 sal_Int32 len = static_cast<sal_Int32>( (e - (edge /2)) * edge1 * 4 );
73 double w = M_PI_2;
74 while (len > 0) {
75 const sal_Int32 alen = (len > edge1 ? edge1 : len);
76 len -= alen;
77 poly = createUnitRect();
78 aTransform.identity();
79 aTransform.scale(
80 ::basegfx::pruneScaleValue( static_cast<double>(alen) / m_sqrtElements ),
81 ::basegfx::pruneScaleValue( 1.0 / m_sqrtElements ) );
82 aTransform.translate(
83 - ::basegfx::pruneScaleValue(
84 static_cast<double>(edge / 2) / m_sqrtElements ),
85 ::basegfx::pruneScaleValue(
86 static_cast<double>(edge / 2) / m_sqrtElements ) );
87 aTransform.rotate( w );
88 w -= M_PI_2;
89 aTransform.translate( 0.5, 0.5 );
90 poly.transform( aTransform );
91 res.append(poly);
95 return res;
98 ::basegfx::B2DPolyPolygon SpiralWipe::operator () ( double t )
100 ::basegfx::B2DPolyPolygon res( createUnitRect() );
101 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
102 innerSpiral.flip();
103 res.append(innerSpiral);
104 return m_flipOnYAxis ? flipOnYAxis(res) : res;
107 ::basegfx::B2DPolyPolygon BoxSnakesWipe::operator () ( double t )
109 ::basegfx::B2DPolyPolygon res( createUnitRect() );
110 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
111 innerSpiral.flip();
113 if (m_fourBox) {
114 ::basegfx::B2DHomMatrix aTransform;
115 aTransform.scale( 0.5, 0.5 );
116 innerSpiral.transform( aTransform );
117 res.append(innerSpiral);
118 res.append( flipOnXAxis(innerSpiral) );
119 innerSpiral = flipOnYAxis(innerSpiral);
120 res.append(innerSpiral);
121 res.append( flipOnXAxis(innerSpiral) );
123 else {
124 ::basegfx::B2DHomMatrix aTransform;
125 aTransform.scale( 1.0, 0.5 );
126 innerSpiral.transform( aTransform );
127 res.append(innerSpiral);
128 res.append( flipOnXAxis(innerSpiral) );
131 return m_flipOnYAxis ? flipOnYAxis(res) : res;