1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_slideshow.hxx" 26 27 #include <canvas/debug.hxx> 28 #include <basegfx/polygon/b2dpolygon.hxx> 29 #include <basegfx/polygon/b2dpolygontools.hxx> 30 #include <basegfx/matrix/b2dhommatrix.hxx> 31 #include <basegfx/matrix/b2dhommatrixtools.hxx> 32 33 #include <cppcanvas/spritecanvas.hxx> 34 35 #include "combtransition.hxx" 36 37 #include <boost/bind.hpp> 38 39 40 namespace slideshow { 41 namespace internal { 42 43 namespace { 44 45 basegfx::B2DPolyPolygon createClipPolygon( 46 const ::basegfx::B2DVector& rDirection, 47 const ::basegfx::B2DSize& rSlideSize, 48 int nNumStrips, int nOffset ) 49 { 50 // create clip polygon in standard orientation (will later 51 // be rotated to match direction vector) 52 ::basegfx::B2DPolyPolygon aClipPoly; 53 54 // create nNumStrips/2 vertical strips 55 for( int i=nOffset; i<nNumStrips; i+=2 ) 56 { 57 aClipPoly.append( 58 ::basegfx::tools::createPolygonFromRect( 59 ::basegfx::B2DRectangle( double(i)/nNumStrips, 0.0, 60 double(i+1)/nNumStrips, 1.0) ) ); 61 62 } 63 64 // rotate polygons, such that the strips are parallel to 65 // the given direction vector 66 const ::basegfx::B2DVector aUpVec(0.0, 1.0); 67 basegfx::B2DHomMatrix aMatrix(basegfx::tools::createRotateAroundPoint(0.5, 0.5, aUpVec.angle( rDirection ))); 68 69 // blow up clip polygon to slide size 70 aMatrix.scale( rSlideSize.getX(), 71 rSlideSize.getY() ); 72 73 aClipPoly.transform( aMatrix ); 74 75 return aClipPoly; 76 } 77 78 } 79 80 CombTransition::CombTransition( 81 boost::optional<SlideSharedPtr> const & leavingSlide, 82 const SlideSharedPtr& pEnteringSlide, 83 const SoundPlayerSharedPtr& pSoundPlayer, 84 const UnoViewContainer& rViewContainer, 85 ScreenUpdater& rScreenUpdater, 86 EventMultiplexer& rEventMultiplexer, 87 const ::basegfx::B2DVector& rPushDirection, 88 sal_Int32 nNumStripes ) 89 : SlideChangeBase( leavingSlide, pEnteringSlide, pSoundPlayer, 90 rViewContainer, rScreenUpdater, rEventMultiplexer, 91 false /* no leaving sprite */, 92 false /* no entering sprite */ ), 93 maPushDirectionUnit( rPushDirection ), 94 mnNumStripes( nNumStripes ) 95 { 96 } 97 98 void CombTransition::renderComb( double t, 99 const ViewEntry& rViewEntry ) const 100 { 101 const SlideBitmapSharedPtr& pEnteringBitmap = getEnteringBitmap(rViewEntry); 102 const cppcanvas::CanvasSharedPtr pCanvas_ = rViewEntry.mpView->getCanvas(); 103 104 if( !pEnteringBitmap || !pCanvas_ ) 105 return; 106 107 // calc bitmap offsets. The enter/leaving bitmaps are only 108 // as large as the actual slides. For scaled-down 109 // presentations, we have to move the left, top edge of 110 // those bitmaps to the actual position, governed by the 111 // given view transform. The aBitmapPosPixel local 112 // variable is already in device coordinate space 113 // (i.e. pixel). 114 115 // TODO(F2): Properly respect clip here. Might have to be transformed, too. 116 const basegfx::B2DHomMatrix viewTransform( rViewEntry.mpView->getTransformation() ); 117 const basegfx::B2DPoint pageOrigin( viewTransform * basegfx::B2DPoint() ); 118 119 // change transformation on cloned canvas to be in 120 // device pixel 121 cppcanvas::CanvasSharedPtr pCanvas( pCanvas_->clone() ); 122 basegfx::B2DPoint p; 123 124 // TODO(Q2): Use basegfx bitmaps here 125 // TODO(F1): SlideBitmap is not fully portable between different canvases! 126 127 const basegfx::B2DSize enteringSizePixel( 128 getEnteringSlideSizePixel( rViewEntry.mpView) ); 129 130 const basegfx::B2DVector aPushDirection = basegfx::B2DVector( 131 enteringSizePixel * maPushDirectionUnit ); 132 const basegfx::B2DPolyPolygon aClipPolygon1 = basegfx::B2DPolyPolygon( 133 createClipPolygon( maPushDirectionUnit, 134 enteringSizePixel, 135 mnNumStripes, 0 ) ); 136 const basegfx::B2DPolyPolygon aClipPolygon2 = basegfx::B2DPolyPolygon( 137 createClipPolygon( maPushDirectionUnit, 138 enteringSizePixel, 139 mnNumStripes, 1 ) ); 140 141 SlideBitmapSharedPtr const & pLeavingBitmap = getLeavingBitmap(rViewEntry); 142 if( pLeavingBitmap ) 143 { 144 // render odd strips: 145 pLeavingBitmap->clip( aClipPolygon1 ); 146 // don't modify bitmap object (no move!): 147 p = basegfx::B2DPoint( pageOrigin + (t * aPushDirection) ); 148 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY())); 149 pLeavingBitmap->draw( pCanvas ); 150 151 // render even strips: 152 pLeavingBitmap->clip( aClipPolygon2 ); 153 // don't modify bitmap object (no move!): 154 p = basegfx::B2DPoint( pageOrigin - (t * aPushDirection) ); 155 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY())); 156 pLeavingBitmap->draw( pCanvas ); 157 } 158 159 // TODO(Q2): Use basegfx bitmaps here 160 // TODO(F1): SlideBitmap is not fully portable between different canvases! 161 162 // render odd strips: 163 pEnteringBitmap->clip( aClipPolygon1 ); 164 // don't modify bitmap object (no move!): 165 p = basegfx::B2DPoint( pageOrigin + ((t - 1.0) * aPushDirection) ); 166 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY())); 167 pEnteringBitmap->draw( pCanvas ); 168 169 // render even strips: 170 pEnteringBitmap->clip( aClipPolygon2 ); 171 // don't modify bitmap object (no move!): 172 p = basegfx::B2DPoint( pageOrigin + ((1.0 - t) * aPushDirection) ); 173 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY())); 174 pEnteringBitmap->draw( pCanvas ); 175 } 176 177 bool CombTransition::operator()( double t ) 178 { 179 std::for_each( beginViews(), 180 endViews(), 181 boost::bind( &CombTransition::renderComb, 182 this, 183 t, 184 _1 )); 185 186 getScreenUpdater().notifyUpdate(); 187 188 return true; 189 } 190 191 } // namespace internal 192 } // namespace presentation 193