1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: combtransition.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 #include <canvas/debug.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <cppcanvas/spritecanvas.hxx>
41 #include "combtransition.hxx"
43 #include <boost/bind.hpp>
51 basegfx::B2DPolyPolygon
createClipPolygon(
52 const ::basegfx::B2DVector
& rDirection
,
53 const ::basegfx::B2DSize
& rSlideSize
,
54 int nNumStrips
, int nOffset
)
56 // create clip polygon in standard orientation (will later
57 // be rotated to match direction vector)
58 ::basegfx::B2DPolyPolygon aClipPoly
;
60 // create nNumStrips/2 vertical strips
61 for( int i
=nOffset
; i
<nNumStrips
; i
+=2 )
64 ::basegfx::tools::createPolygonFromRect(
65 ::basegfx::B2DRectangle( double(i
)/nNumStrips
, 0.0,
66 double(i
+1)/nNumStrips
, 1.0) ) );
70 // rotate polygons, such that the strips are parallel to
71 // the given direction vector
72 const ::basegfx::B2DVector
aUpVec(0.0, 1.0);
73 ::basegfx::B2DHomMatrix aMatrix
;
75 aMatrix
.translate( -0.5, -0.5 );
76 aMatrix
.rotate( aUpVec
.angle( rDirection
) );
77 aMatrix
.translate( 0.5, 0.5 );
79 // blow up clip polygon to slide size
80 aMatrix
.scale( rSlideSize
.getX(),
83 aClipPoly
.transform( aMatrix
);
90 CombTransition::CombTransition(
91 boost::optional
<SlideSharedPtr
> const & leavingSlide
,
92 const SlideSharedPtr
& pEnteringSlide
,
93 const SoundPlayerSharedPtr
& pSoundPlayer
,
94 const UnoViewContainer
& rViewContainer
,
95 ScreenUpdater
& rScreenUpdater
,
96 EventMultiplexer
& rEventMultiplexer
,
97 const ::basegfx::B2DVector
& rPushDirection
,
98 sal_Int32 nNumStripes
)
99 : SlideChangeBase( leavingSlide
, pEnteringSlide
, pSoundPlayer
,
100 rViewContainer
, rScreenUpdater
, rEventMultiplexer
,
101 false /* no leaving sprite */,
102 false /* no entering sprite */ ),
103 maPushDirectionUnit( rPushDirection
),
104 mnNumStripes( nNumStripes
)
108 void CombTransition::renderComb( double t
,
109 const ViewEntry
& rViewEntry
) const
111 const SlideBitmapSharedPtr
& pEnteringBitmap
= getEnteringBitmap(rViewEntry
);
112 const cppcanvas::CanvasSharedPtr pCanvas_
= rViewEntry
.mpView
->getCanvas();
114 if( !pEnteringBitmap
|| !pCanvas_
)
117 // calc bitmap offsets. The enter/leaving bitmaps are only
118 // as large as the actual slides. For scaled-down
119 // presentations, we have to move the left, top edge of
120 // those bitmaps to the actual position, governed by the
121 // given view transform. The aBitmapPosPixel local
122 // variable is already in device coordinate space
125 // TODO(F2): Properly respect clip here. Might have to be transformed, too.
126 const basegfx::B2DHomMatrix
viewTransform( rViewEntry
.mpView
->getTransformation() );
127 const basegfx::B2DPoint
pageOrigin( viewTransform
* basegfx::B2DPoint() );
129 // change transformation on cloned canvas to be in
131 cppcanvas::CanvasSharedPtr
pCanvas( pCanvas_
->clone() );
132 basegfx::B2DHomMatrix transform
;
135 // TODO(Q2): Use basegfx bitmaps here
136 // TODO(F1): SlideBitmap is not fully portable between different canvases!
138 const basegfx::B2DSize
enteringSizePixel(
139 getEnteringSlideSizePixel( rViewEntry
.mpView
) );
141 const basegfx::B2DVector aPushDirection
= basegfx::B2DVector(
142 enteringSizePixel
* maPushDirectionUnit
);
143 const basegfx::B2DPolyPolygon aClipPolygon1
= basegfx::B2DPolyPolygon(
144 createClipPolygon( maPushDirectionUnit
,
147 const basegfx::B2DPolyPolygon aClipPolygon2
= basegfx::B2DPolyPolygon(
148 createClipPolygon( maPushDirectionUnit
,
152 SlideBitmapSharedPtr
const & pLeavingBitmap
= getLeavingBitmap(rViewEntry
);
155 // render odd strips:
156 pLeavingBitmap
->clip( aClipPolygon1
);
157 // don't modify bitmap object (no move!):
158 p
= basegfx::B2DPoint( pageOrigin
+ (t
* aPushDirection
) );
159 transform
.translate( p
.getX(), p
.getY() );
160 pCanvas
->setTransformation( transform
);
161 pLeavingBitmap
->draw( pCanvas
);
163 // render even strips:
164 pLeavingBitmap
->clip( aClipPolygon2
);
165 // don't modify bitmap object (no move!):
166 transform
.identity();
167 p
= basegfx::B2DPoint( pageOrigin
- (t
* aPushDirection
) );
168 transform
.translate( p
.getX(), p
.getY() );
169 pCanvas
->setTransformation( transform
);
170 pLeavingBitmap
->draw( pCanvas
);
173 // TODO(Q2): Use basegfx bitmaps here
174 // TODO(F1): SlideBitmap is not fully portable between different canvases!
176 // render odd strips:
177 pEnteringBitmap
->clip( aClipPolygon1
);
178 // don't modify bitmap object (no move!):
179 transform
.identity();
180 p
= basegfx::B2DPoint( pageOrigin
+ ((t
- 1.0) * aPushDirection
) );
181 transform
.translate( p
.getX(), p
.getY() );
182 pCanvas
->setTransformation( transform
);
183 pEnteringBitmap
->draw( pCanvas
);
185 // render even strips:
186 pEnteringBitmap
->clip( aClipPolygon2
);
187 // don't modify bitmap object (no move!):
188 transform
.identity();
189 p
= basegfx::B2DPoint( pageOrigin
+ ((1.0 - t
) * aPushDirection
) );
190 transform
.translate( p
.getX(), p
.getY() );
191 pCanvas
->setTransformation( transform
);
192 pEnteringBitmap
->draw( pCanvas
);
195 bool CombTransition::operator()( double t
)
197 std::for_each( beginViews(),
199 boost::bind( &CombTransition::renderComb
,
204 getScreenUpdater().notifyUpdate();
209 } // namespace internal
210 } // namespace presentation