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