bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / engine / transitions / combtransition.cxx
blobabd632069135b41757f8f9d06151d6a3b447a73c
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 <canvas/debug.hxx>
22 #include <basegfx/polygon/b2dpolygon.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 #include <cppcanvas/spritecanvas.hxx>
29 #include "combtransition.hxx"
31 #include <boost/bind.hpp>
34 namespace slideshow {
35 namespace internal {
37 namespace {
39 basegfx::B2DPolyPolygon createClipPolygon(
40 const ::basegfx::B2DVector& rDirection,
41 const ::basegfx::B2DSize& rSlideSize,
42 int nNumStrips, int nOffset )
44 // create clip polygon in standard orientation (will later
45 // be rotated to match direction vector)
46 ::basegfx::B2DPolyPolygon aClipPoly;
48 // create nNumStrips/2 vertical strips
49 for( int i=nOffset; i<nNumStrips; i+=2 )
51 aClipPoly.append(
52 ::basegfx::tools::createPolygonFromRect(
53 ::basegfx::B2DRectangle( double(i)/nNumStrips, 0.0,
54 double(i+1)/nNumStrips, 1.0) ) );
58 // rotate polygons, such that the strips are parallel to
59 // the given direction vector
60 const ::basegfx::B2DVector aUpVec(0.0, 1.0);
61 basegfx::B2DHomMatrix aMatrix(basegfx::tools::createRotateAroundPoint(0.5, 0.5, aUpVec.angle( rDirection )));
63 // blow up clip polygon to slide size
64 aMatrix.scale( rSlideSize.getX(),
65 rSlideSize.getY() );
67 aClipPoly.transform( aMatrix );
69 return aClipPoly;
74 CombTransition::CombTransition(
75 boost::optional<SlideSharedPtr> const & leavingSlide,
76 const SlideSharedPtr& pEnteringSlide,
77 const SoundPlayerSharedPtr& pSoundPlayer,
78 const UnoViewContainer& rViewContainer,
79 ScreenUpdater& rScreenUpdater,
80 EventMultiplexer& rEventMultiplexer,
81 const ::basegfx::B2DVector& rPushDirection,
82 sal_Int32 nNumStripes )
83 : SlideChangeBase( leavingSlide, pEnteringSlide, pSoundPlayer,
84 rViewContainer, rScreenUpdater, rEventMultiplexer,
85 false /* no leaving sprite */,
86 false /* no entering sprite */ ),
87 maPushDirectionUnit( rPushDirection ),
88 mnNumStripes( nNumStripes )
92 void CombTransition::renderComb( double t,
93 const ViewEntry& rViewEntry ) const
95 const SlideBitmapSharedPtr& pEnteringBitmap = getEnteringBitmap(rViewEntry);
96 const cppcanvas::CanvasSharedPtr pCanvas_ = rViewEntry.mpView->getCanvas();
98 if( !pEnteringBitmap || !pCanvas_ )
99 return;
101 // calc bitmap offsets. The enter/leaving bitmaps are only
102 // as large as the actual slides. For scaled-down
103 // presentations, we have to move the left, top edge of
104 // those bitmaps to the actual position, governed by the
105 // given view transform. The aBitmapPosPixel local
106 // variable is already in device coordinate space
107 // (i.e. pixel).
109 // TODO(F2): Properly respect clip here. Might have to be transformed, too.
110 const basegfx::B2DHomMatrix viewTransform( rViewEntry.mpView->getTransformation() );
111 const basegfx::B2DPoint pageOrigin( viewTransform * basegfx::B2DPoint() );
113 // change transformation on cloned canvas to be in
114 // device pixel
115 cppcanvas::CanvasSharedPtr pCanvas( pCanvas_->clone() );
116 basegfx::B2DPoint p;
118 // TODO(Q2): Use basegfx bitmaps here
119 // TODO(F1): SlideBitmap is not fully portable between different canvases!
121 const basegfx::B2DSize enteringSizePixel(
122 getEnteringSlideSizePixel( rViewEntry.mpView) );
124 const basegfx::B2DVector aPushDirection = basegfx::B2DVector(
125 enteringSizePixel * maPushDirectionUnit );
126 const basegfx::B2DPolyPolygon aClipPolygon1 = basegfx::B2DPolyPolygon(
127 createClipPolygon( maPushDirectionUnit,
128 enteringSizePixel,
129 mnNumStripes, 0 ) );
130 const basegfx::B2DPolyPolygon aClipPolygon2 = basegfx::B2DPolyPolygon(
131 createClipPolygon( maPushDirectionUnit,
132 enteringSizePixel,
133 mnNumStripes, 1 ) );
135 SlideBitmapSharedPtr const & pLeavingBitmap = getLeavingBitmap(rViewEntry);
136 if( pLeavingBitmap )
138 // render odd strips:
139 pLeavingBitmap->clip( aClipPolygon1 );
140 // don't modify bitmap object (no move!):
141 p = basegfx::B2DPoint( pageOrigin + (t * aPushDirection) );
142 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY()));
143 pLeavingBitmap->draw( pCanvas );
145 // render even strips:
146 pLeavingBitmap->clip( aClipPolygon2 );
147 // don't modify bitmap object (no move!):
148 p = basegfx::B2DPoint( pageOrigin - (t * aPushDirection) );
149 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY()));
150 pLeavingBitmap->draw( pCanvas );
153 // TODO(Q2): Use basegfx bitmaps here
154 // TODO(F1): SlideBitmap is not fully portable between different canvases!
156 // render odd strips:
157 pEnteringBitmap->clip( aClipPolygon1 );
158 // don't modify bitmap object (no move!):
159 p = basegfx::B2DPoint( pageOrigin + ((t - 1.0) * aPushDirection) );
160 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY()));
161 pEnteringBitmap->draw( pCanvas );
163 // render even strips:
164 pEnteringBitmap->clip( aClipPolygon2 );
165 // don't modify bitmap object (no move!):
166 p = basegfx::B2DPoint( pageOrigin + ((1.0 - t) * aPushDirection) );
167 pCanvas->setTransformation(basegfx::tools::createTranslateB2DHomMatrix(p.getX(), p.getY()));
168 pEnteringBitmap->draw( pCanvas );
171 bool CombTransition::operator()( double t )
173 std::for_each( beginViews(),
174 endViews(),
175 boost::bind( &CombTransition::renderComb,
176 this,
178 _1 ));
180 getScreenUpdater().notifyUpdate();
182 return true;
185 } // namespace internal
186 } // namespace presentation
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */