Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / transitions / combtransition.cxx
blob4185b5033752c589b824e6a494ec38f23748a766
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 <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 #include <cppcanvas/spritecanvas.hxx>
28 #include "combtransition.hxx"
30 namespace slideshow {
31 namespace internal {
33 namespace {
35 basegfx::B2DPolyPolygon createClipPolygon(
36 const ::basegfx::B2DVector& rDirection,
37 const ::basegfx::B2DSize& rSlideSize,
38 int nNumStrips, int nOffset )
40 // create clip polygon in standard orientation (will later
41 // be rotated to match direction vector)
42 ::basegfx::B2DPolyPolygon aClipPoly;
44 // create nNumStrips/2 vertical strips
45 for( int i=nOffset; i<nNumStrips; i+=2 )
47 aClipPoly.append(
48 ::basegfx::utils::createPolygonFromRect(
49 ::basegfx::B2DRectangle( double(i)/nNumStrips, 0.0,
50 double(i+1)/nNumStrips, 1.0) ) );
54 // rotate polygons, such that the strips are parallel to
55 // the given direction vector
56 const ::basegfx::B2DVector aUpVec(0.0, 1.0);
57 basegfx::B2DHomMatrix aMatrix(basegfx::utils::createRotateAroundPoint(0.5, 0.5, aUpVec.angle( rDirection )));
59 // blow up clip polygon to slide size
60 aMatrix.scale( rSlideSize.getX(),
61 rSlideSize.getY() );
63 aClipPoly.transform( aMatrix );
65 return aClipPoly;
70 CombTransition::CombTransition(
71 boost::optional<SlideSharedPtr> const & leavingSlide,
72 const SlideSharedPtr& pEnteringSlide,
73 const SoundPlayerSharedPtr& pSoundPlayer,
74 const UnoViewContainer& rViewContainer,
75 ScreenUpdater& rScreenUpdater,
76 EventMultiplexer& rEventMultiplexer,
77 const ::basegfx::B2DVector& rPushDirection,
78 sal_Int32 nNumStripes )
79 : SlideChangeBase( leavingSlide, pEnteringSlide, pSoundPlayer,
80 rViewContainer, rScreenUpdater, rEventMultiplexer,
81 false /* no leaving sprite */,
82 false /* no entering sprite */ ),
83 maPushDirectionUnit( rPushDirection ),
84 mnNumStripes( nNumStripes )
88 void CombTransition::renderComb( double t,
89 const ViewEntry& rViewEntry ) const
91 const SlideBitmapSharedPtr& pEnteringBitmap = getEnteringBitmap(rViewEntry);
92 const cppcanvas::CanvasSharedPtr pCanvas_ = rViewEntry.mpView->getCanvas();
94 if( !pEnteringBitmap || !pCanvas_ )
95 return;
97 // calc bitmap offsets. The enter/leaving bitmaps are only
98 // as large as the actual slides. For scaled-down
99 // presentations, we have to move the left, top edge of
100 // those bitmaps to the actual position, governed by the
101 // given view transform. The aBitmapPosPixel local
102 // variable is already in device coordinate space
103 // (i.e. pixel).
105 // TODO(F2): Properly respect clip here. Might have to be transformed, too.
106 const basegfx::B2DHomMatrix viewTransform( rViewEntry.mpView->getTransformation() );
107 const basegfx::B2DPoint pageOrigin( viewTransform * basegfx::B2DPoint() );
109 // change transformation on cloned canvas to be in
110 // device pixel
111 cppcanvas::CanvasSharedPtr pCanvas( pCanvas_->clone() );
112 basegfx::B2DPoint p;
114 // TODO(Q2): Use basegfx bitmaps here
115 // TODO(F1): SlideBitmap is not fully portable between different canvases!
117 const basegfx::B2DSize enteringSizePixel(
118 getEnteringSlideSizePixel( rViewEntry.mpView) );
120 const basegfx::B2DVector aPushDirection = basegfx::B2DVector(
121 enteringSizePixel * maPushDirectionUnit );
122 const basegfx::B2DPolyPolygon aClipPolygon1 =
123 createClipPolygon( maPushDirectionUnit,
124 enteringSizePixel,
125 mnNumStripes, 0 );
126 const basegfx::B2DPolyPolygon aClipPolygon2 =
127 createClipPolygon( maPushDirectionUnit,
128 enteringSizePixel,
129 mnNumStripes, 1 );
131 SlideBitmapSharedPtr const & pLeavingBitmap = getLeavingBitmap(rViewEntry);
132 if( pLeavingBitmap )
134 // render odd strips:
135 pLeavingBitmap->clip( aClipPolygon1 );
136 // don't modify bitmap object (no move!):
137 p = basegfx::B2DPoint( pageOrigin + (t * aPushDirection) );
138 pCanvas->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p.getX(), p.getY()));
139 pLeavingBitmap->draw( pCanvas );
141 // render even strips:
142 pLeavingBitmap->clip( aClipPolygon2 );
143 // don't modify bitmap object (no move!):
144 p = basegfx::B2DPoint( pageOrigin - (t * aPushDirection) );
145 pCanvas->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p.getX(), p.getY()));
146 pLeavingBitmap->draw( pCanvas );
149 // TODO(Q2): Use basegfx bitmaps here
150 // TODO(F1): SlideBitmap is not fully portable between different canvases!
152 // render odd strips:
153 pEnteringBitmap->clip( aClipPolygon1 );
154 // don't modify bitmap object (no move!):
155 p = basegfx::B2DPoint( pageOrigin + ((t - 1.0) * aPushDirection) );
156 pCanvas->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p.getX(), p.getY()));
157 pEnteringBitmap->draw( pCanvas );
159 // render even strips:
160 pEnteringBitmap->clip( aClipPolygon2 );
161 // don't modify bitmap object (no move!):
162 p = basegfx::B2DPoint( pageOrigin + ((1.0 - t) * aPushDirection) );
163 pCanvas->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p.getX(), p.getY()));
164 pEnteringBitmap->draw( pCanvas );
167 bool CombTransition::operator()( double t )
169 std::for_each( beginViews(),
170 endViews(),
171 [this, &t]( const ViewEntry& rViewEntry )
172 { return this->renderComb( t, rViewEntry ); } );
174 getScreenUpdater().notifyUpdate();
176 return true;
179 } // namespace internal
180 } // namespace presentation
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */