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