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 <tools/diagnose_ex.h>
29cdf0e10cSrcweir #include <canvas/canvastools.hxx>
30cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
31cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
34cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "slidechangebase.hxx"
37cdf0e10cSrcweir #include "tools.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <boost/bind.hpp>
40cdf0e10cSrcweir #include <algorithm>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace com::sun::star;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace slideshow {
45cdf0e10cSrcweir namespace internal {
46cdf0e10cSrcweir 
SlideChangeBase(boost::optional<SlideSharedPtr> const & leavingSlide,const SlideSharedPtr & pEnteringSlide,const SoundPlayerSharedPtr & pSoundPlayer,const UnoViewContainer & rViewContainer,ScreenUpdater & rScreenUpdater,EventMultiplexer & rEventMultiplexer,bool bCreateLeavingSprites,bool bCreateEnteringSprites)47cdf0e10cSrcweir SlideChangeBase::SlideChangeBase( boost::optional<SlideSharedPtr> const & leavingSlide,
48cdf0e10cSrcweir                                   const SlideSharedPtr&                   pEnteringSlide,
49cdf0e10cSrcweir                                   const SoundPlayerSharedPtr&             pSoundPlayer,
50cdf0e10cSrcweir                                   const UnoViewContainer&                 rViewContainer,
51cdf0e10cSrcweir                                   ScreenUpdater&                          rScreenUpdater,
52cdf0e10cSrcweir                                   EventMultiplexer&                       rEventMultiplexer,
53cdf0e10cSrcweir                                   bool                                    bCreateLeavingSprites,
54cdf0e10cSrcweir                                   bool                                    bCreateEnteringSprites ) :
55cdf0e10cSrcweir       mpSoundPlayer( pSoundPlayer ),
56cdf0e10cSrcweir       mrEventMultiplexer(rEventMultiplexer),
57cdf0e10cSrcweir       mrScreenUpdater(rScreenUpdater),
58cdf0e10cSrcweir       maLeavingSlide( leavingSlide ),
59cdf0e10cSrcweir       mpEnteringSlide( pEnteringSlide ),
60cdf0e10cSrcweir       maViewData(),
61cdf0e10cSrcweir       mrViewContainer(rViewContainer),
62cdf0e10cSrcweir       mbCreateLeavingSprites(bCreateLeavingSprites),
63cdf0e10cSrcweir       mbCreateEnteringSprites(bCreateEnteringSprites),
64cdf0e10cSrcweir       mbSpritesVisible(false),
65cdf0e10cSrcweir       mbFinished(false),
66cdf0e10cSrcweir       mbPrefetched(false)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     ENSURE_OR_THROW(
69cdf0e10cSrcweir         pEnteringSlide,
70cdf0e10cSrcweir         "SlideChangeBase::SlideChangeBase(): Invalid entering slide!" );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
getLeavingBitmap(const ViewEntry & rViewEntry) const73cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::getLeavingBitmap( const ViewEntry& rViewEntry ) const
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if( !rViewEntry.mpLeavingBitmap )
76cdf0e10cSrcweir         rViewEntry.mpLeavingBitmap = createBitmap(rViewEntry.mpView,
77cdf0e10cSrcweir                                                   maLeavingSlide);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     return rViewEntry.mpLeavingBitmap;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
getEnteringBitmap(const ViewEntry & rViewEntry) const82cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::getEnteringBitmap( const ViewEntry& rViewEntry ) const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     if( !rViewEntry.mpEnteringBitmap )
85cdf0e10cSrcweir         rViewEntry.mpEnteringBitmap = createBitmap( rViewEntry.mpView,
86cdf0e10cSrcweir                                                     boost::optional<SlideSharedPtr>(mpEnteringSlide) );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     return rViewEntry.mpEnteringBitmap;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
createBitmap(const UnoViewSharedPtr & rView,const boost::optional<SlideSharedPtr> & rSlide) const91cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::createBitmap( const UnoViewSharedPtr&                rView,
92cdf0e10cSrcweir                                                     const boost::optional<SlideSharedPtr>& rSlide ) const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     SlideBitmapSharedPtr pRet;
95cdf0e10cSrcweir     if( !rSlide )
96cdf0e10cSrcweir         return pRet;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     SlideSharedPtr const & pSlide = *rSlide;
99cdf0e10cSrcweir     if( !pSlide )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         // TODO(P3): No need to generate a bitmap here. This only made
102cdf0e10cSrcweir         // the code more uniform. Faster would be to simply clear the
103cdf0e10cSrcweir         // sprite to black.
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         // create empty, black-filled bitmap
106cdf0e10cSrcweir         const basegfx::B2ISize slideSizePixel(
107cdf0e10cSrcweir             getSlideSizePixel( mpEnteringSlide->getSlideSize(),
108cdf0e10cSrcweir                                rView ));
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         cppcanvas::CanvasSharedPtr pCanvas( rView->getCanvas() );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         // create a bitmap of appropriate size
113cdf0e10cSrcweir         cppcanvas::BitmapSharedPtr pBitmap(
114cdf0e10cSrcweir             cppcanvas::BaseGfxFactory::getInstance().createBitmap(
115cdf0e10cSrcweir                 pCanvas,
116cdf0e10cSrcweir                 slideSizePixel ) );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         ENSURE_OR_THROW(
119cdf0e10cSrcweir             pBitmap,
120cdf0e10cSrcweir             "SlideChangeBase::createBitmap(): Cannot create page bitmap" );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         cppcanvas::BitmapCanvasSharedPtr pBitmapCanvas(
123cdf0e10cSrcweir             pBitmap->getBitmapCanvas() );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         ENSURE_OR_THROW( pBitmapCanvas,
126cdf0e10cSrcweir                           "SlideChangeBase::createBitmap(): "
127cdf0e10cSrcweir                           "Cannot create page bitmap canvas" );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         // set transformation to identitiy (->device pixel)
130cdf0e10cSrcweir         pBitmapCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // clear bitmap to black
133cdf0e10cSrcweir         fillRect( pBitmapCanvas,
134cdf0e10cSrcweir                   ::basegfx::B2DRectangle( 0.0, 0.0,
135cdf0e10cSrcweir                                            slideSizePixel.getX(),
136cdf0e10cSrcweir                                            slideSizePixel.getY() ),
137cdf0e10cSrcweir                   0x000000FFU );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         pRet.reset( new SlideBitmap( pBitmap ));
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir     else
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         pRet = pSlide->getCurrentSlideBitmap( rView );
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     return pRet;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
getEnteringSlideSizePixel(const UnoViewSharedPtr & pView) const149cdf0e10cSrcweir ::basegfx::B2ISize SlideChangeBase::getEnteringSlideSizePixel( const UnoViewSharedPtr& pView ) const
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     return getSlideSizePixel( mpEnteringSlide->getSlideSize(),
152cdf0e10cSrcweir                               pView );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
getLeavingSlideSizePixel(const UnoViewSharedPtr & pView) const155cdf0e10cSrcweir ::basegfx::B2ISize SlideChangeBase::getLeavingSlideSizePixel( const UnoViewSharedPtr& pView ) const
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     return getSlideSizePixel( (*maLeavingSlide)->getSlideSize(),
158cdf0e10cSrcweir                               pView );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
renderBitmap(SlideBitmapSharedPtr const & pSlideBitmap,cppcanvas::CanvasSharedPtr const & pCanvas)162cdf0e10cSrcweir void SlideChangeBase::renderBitmap(
163cdf0e10cSrcweir     SlideBitmapSharedPtr const & pSlideBitmap,
164cdf0e10cSrcweir     cppcanvas::CanvasSharedPtr const & pCanvas )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     if( pSlideBitmap && pCanvas )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         // need to render without any transformation (we
169cdf0e10cSrcweir         // assume device units):
170cdf0e10cSrcweir         const basegfx::B2DHomMatrix viewTransform(
171cdf0e10cSrcweir             pCanvas->getTransformation() );
172cdf0e10cSrcweir         const basegfx::B2DPoint pageOrigin(
173cdf0e10cSrcweir             viewTransform * basegfx::B2DPoint() );
174cdf0e10cSrcweir         const cppcanvas::CanvasSharedPtr pDevicePixelCanvas(
175cdf0e10cSrcweir             pCanvas->clone() );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         // render at output position, don't modify bitmap object (no move!):
178cdf0e10cSrcweir         const basegfx::B2DHomMatrix transform(basegfx::tools::createTranslateB2DHomMatrix(
179cdf0e10cSrcweir             pageOrigin.getX(), pageOrigin.getY()));
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         pDevicePixelCanvas->setTransformation( transform );
182cdf0e10cSrcweir         pSlideBitmap->draw( pDevicePixelCanvas );
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
prefetch(const AnimatableShapeSharedPtr &,const ShapeAttributeLayerSharedPtr &)186cdf0e10cSrcweir void SlideChangeBase::prefetch( const AnimatableShapeSharedPtr&,
187cdf0e10cSrcweir                                 const ShapeAttributeLayerSharedPtr& )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     // we're a one-shot activity, and already finished
190cdf0e10cSrcweir     if( mbFinished || mbPrefetched )
191cdf0e10cSrcweir         return;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     // register ourselves for view change events
194cdf0e10cSrcweir     mrEventMultiplexer.addViewHandler( shared_from_this() );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     // init views and create slide bitmaps
197cdf0e10cSrcweir     std::for_each( mrViewContainer.begin(),
198cdf0e10cSrcweir                    mrViewContainer.end(),
199cdf0e10cSrcweir                    boost::bind( &SlideChangeBase::viewAdded,
200cdf0e10cSrcweir                                 this,
201cdf0e10cSrcweir                                 _1 ));
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     mbPrefetched = true;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
start(const AnimatableShapeSharedPtr & rShape,const ShapeAttributeLayerSharedPtr & rLayer)206cdf0e10cSrcweir void SlideChangeBase::start( const AnimatableShapeSharedPtr&     rShape,
207cdf0e10cSrcweir                              const ShapeAttributeLayerSharedPtr& rLayer )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     // we're a one-shot activity, and already finished
210cdf0e10cSrcweir     if( mbFinished )
211cdf0e10cSrcweir         return;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     prefetch(rShape,rLayer); // no-op, if already done
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     // start accompanying sound effect, if any
216cdf0e10cSrcweir     if( mpSoundPlayer )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         mpSoundPlayer->startPlayback();
219cdf0e10cSrcweir         // xxx todo: for now, presentation.cxx takes care about the slide
220cdf0e10cSrcweir         // #i50492#  transition sound object, so just release it here
221cdf0e10cSrcweir         mpSoundPlayer.reset();
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
end()225cdf0e10cSrcweir void SlideChangeBase::end()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     // we're a one-shot activity, and already finished
228cdf0e10cSrcweir     if( mbFinished )
229cdf0e10cSrcweir         return;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     try
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         // draw fully entered bitmap:
234cdf0e10cSrcweir         ViewsVecT::const_iterator aCurr( beginViews() );
235cdf0e10cSrcweir         const ViewsVecT::const_iterator aEnd( endViews() );
236cdf0e10cSrcweir         while( aCurr != aEnd )
237cdf0e10cSrcweir         {
238cdf0e10cSrcweir             // fully clear view content to background color
239cdf0e10cSrcweir             aCurr->mpView->clearAll();
240cdf0e10cSrcweir 
241cdf0e10cSrcweir             const SlideBitmapSharedPtr pSlideBitmap( getEnteringBitmap( *aCurr ));
242cdf0e10cSrcweir             pSlideBitmap->clip( basegfx::B2DPolyPolygon() /* no clipping */ );
243cdf0e10cSrcweir             renderBitmap( pSlideBitmap,
244cdf0e10cSrcweir                           aCurr->mpView->getCanvas() );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir             ++aCurr;
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir     catch( uno::Exception& )
250cdf0e10cSrcweir     {
251cdf0e10cSrcweir         // make sure releasing below happens
252cdf0e10cSrcweir     }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     // swap changes to screen
255cdf0e10cSrcweir     mrScreenUpdater.notifyUpdate();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     // make object dysfunctional
258cdf0e10cSrcweir     mbFinished = true;
259cdf0e10cSrcweir     ViewsVecT().swap(maViewData);
260cdf0e10cSrcweir     maLeavingSlide.reset();
261cdf0e10cSrcweir     mpEnteringSlide.reset();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     // sprites have been binned above
264cdf0e10cSrcweir     mbSpritesVisible = false;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     // remove also from event multiplexer, we're dead anyway
267cdf0e10cSrcweir     mrEventMultiplexer.removeViewHandler( shared_from_this() );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
operator ()(double nValue)270cdf0e10cSrcweir bool SlideChangeBase::operator()( double nValue )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     if( mbFinished )
273cdf0e10cSrcweir         return false;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     const std::size_t nEntries( maViewData.size() );
276cdf0e10cSrcweir     bool bSpritesVisible( mbSpritesVisible );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     for( ::std::size_t i=0; i<nEntries; ++i )
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         // calc sprite offsets. The enter/leaving bitmaps are only
281cdf0e10cSrcweir         // as large as the actual slides. For scaled-down
282cdf0e10cSrcweir         // presentations, we have to move the left, top edge of
283cdf0e10cSrcweir         // those bitmaps to the actual position, governed by the
284cdf0e10cSrcweir         // given view transform. The aSpritePosPixel local
285cdf0e10cSrcweir         // variable is already in device coordinate space
286cdf0e10cSrcweir         // (i.e. pixel).
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         ViewEntry& rViewEntry( maViewData[i] );
289cdf0e10cSrcweir         const ::cppcanvas::CanvasSharedPtr& rCanvas( rViewEntry.mpView->getCanvas() );
290cdf0e10cSrcweir         ::cppcanvas::CustomSpriteSharedPtr& rInSprite( rViewEntry.mpInSprite );
291cdf0e10cSrcweir         ::cppcanvas::CustomSpriteSharedPtr& rOutSprite( rViewEntry.mpOutSprite );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         // TODO(F2): Properly respect clip here.
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         // Might have to be transformed, too.
296cdf0e10cSrcweir         const ::basegfx::B2DHomMatrix aViewTransform(
297cdf0e10cSrcweir             rViewEntry.mpView->getTransformation() );
298cdf0e10cSrcweir         const ::basegfx::B2DPoint aSpritePosPixel(
299cdf0e10cSrcweir             aViewTransform * ::basegfx::B2DPoint() );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         // move sprite to final output position, in
302cdf0e10cSrcweir         // device coordinates
303cdf0e10cSrcweir         if( rOutSprite )
304cdf0e10cSrcweir             rOutSprite->movePixel( aSpritePosPixel );
305cdf0e10cSrcweir         if( rInSprite )
306cdf0e10cSrcweir             rInSprite->movePixel( aSpritePosPixel );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir         if( !mbSpritesVisible )
309cdf0e10cSrcweir         {
310cdf0e10cSrcweir             if( rOutSprite )
311cdf0e10cSrcweir             {
312cdf0e10cSrcweir                 // only render once: clipping is done
313cdf0e10cSrcweir                 // exclusively with the sprite
314cdf0e10cSrcweir                 const ::cppcanvas::CanvasSharedPtr pOutContentCanvas(
315cdf0e10cSrcweir                     rOutSprite->getContentCanvas() );
316cdf0e10cSrcweir                 if( pOutContentCanvas)
317cdf0e10cSrcweir                 {
318cdf0e10cSrcweir                     // TODO(Q2): Use basegfx bitmaps here
319cdf0e10cSrcweir 
320cdf0e10cSrcweir                     // TODO(F1): SlideBitmap is not fully portable
321cdf0e10cSrcweir                     // between different canvases!
322cdf0e10cSrcweir 
323cdf0e10cSrcweir                     // render the content
324cdf0e10cSrcweir                     OSL_ASSERT( getLeavingBitmap( rViewEntry ) );
325cdf0e10cSrcweir                     if( getLeavingBitmap( rViewEntry ) )
326cdf0e10cSrcweir                         getLeavingBitmap( rViewEntry )->draw( pOutContentCanvas );
327cdf0e10cSrcweir                 }
328cdf0e10cSrcweir             }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir             if( rInSprite )
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 // only render once: clipping is done
333cdf0e10cSrcweir                 // exclusively with the sprite
334cdf0e10cSrcweir                 const ::cppcanvas::CanvasSharedPtr pInContentCanvas(
335cdf0e10cSrcweir                     rInSprite->getContentCanvas() );
336cdf0e10cSrcweir                 if( pInContentCanvas )
337cdf0e10cSrcweir                 {
338cdf0e10cSrcweir                     // TODO(Q2): Use basegfx bitmaps here
339cdf0e10cSrcweir 
340cdf0e10cSrcweir                     // TODO(F1): SlideBitmap is not fully portable
341cdf0e10cSrcweir                     // between different canvases!
342cdf0e10cSrcweir 
343cdf0e10cSrcweir                     // render the content
344cdf0e10cSrcweir                     getEnteringBitmap( rViewEntry )->draw( pInContentCanvas );
345cdf0e10cSrcweir                 }
346cdf0e10cSrcweir             }
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         if( rOutSprite )
350cdf0e10cSrcweir             performOut( rOutSprite, rViewEntry, rCanvas, nValue );
351cdf0e10cSrcweir         if( rInSprite )
352cdf0e10cSrcweir             performIn( rInSprite, rViewEntry, rCanvas, nValue );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         // finishing deeds for first run.
355cdf0e10cSrcweir         if( !mbSpritesVisible)
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             // enable sprites:
358cdf0e10cSrcweir             if( rOutSprite )
359cdf0e10cSrcweir                 rOutSprite->show();
360cdf0e10cSrcweir             if( rInSprite )
361cdf0e10cSrcweir                 rInSprite->show();
362cdf0e10cSrcweir             bSpritesVisible = true;
363cdf0e10cSrcweir         }
364cdf0e10cSrcweir     } // for_each( sprite )
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     mbSpritesVisible = bSpritesVisible;
367cdf0e10cSrcweir     mrScreenUpdater.notifyUpdate();
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     return true;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
performIn(const cppcanvas::CustomSpriteSharedPtr &,const ViewEntry &,const cppcanvas::CanvasSharedPtr &,double)372cdf0e10cSrcweir void SlideChangeBase::performIn(
373cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr&   /*rSprite*/,
374cdf0e10cSrcweir     const ViewEntry&                          /*rViewEntry*/,
375cdf0e10cSrcweir     const cppcanvas::CanvasSharedPtr&         /*rDestinationCanvas*/,
376cdf0e10cSrcweir     double                                    /*t*/ )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
performOut(const cppcanvas::CustomSpriteSharedPtr &,const ViewEntry &,const cppcanvas::CanvasSharedPtr &,double)380cdf0e10cSrcweir void SlideChangeBase::performOut(
381cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr&  /*rSprite*/,
382cdf0e10cSrcweir     const ViewEntry&                         /*rViewEntry*/,
383cdf0e10cSrcweir     const cppcanvas::CanvasSharedPtr&        /*rDestinationCanvas*/,
384cdf0e10cSrcweir     double                                   /*t*/ )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
getUnderlyingValue() const388cdf0e10cSrcweir double SlideChangeBase::getUnderlyingValue() const
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     return 0.0;     // though this should be used in concert with
391cdf0e10cSrcweir 				    // ActivitiesFactory::createSimpleActivity, better
392cdf0e10cSrcweir 			    	// explicitely name our start value.
393cdf0e10cSrcweir 				    // Permissible range for operator() above is [0,1]
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
viewAdded(const UnoViewSharedPtr & rView)396cdf0e10cSrcweir void SlideChangeBase::viewAdded( const UnoViewSharedPtr& rView )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir     // we're a one-shot activity, and already finished
399cdf0e10cSrcweir     if( mbFinished )
400cdf0e10cSrcweir         return;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     maViewData.push_back( ViewEntry(rView) );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     ViewEntry& rEntry( maViewData.back() );
405cdf0e10cSrcweir     getEnteringBitmap( rEntry );
406cdf0e10cSrcweir     getLeavingBitmap( rEntry );
407cdf0e10cSrcweir     addSprites( rEntry );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
viewRemoved(const UnoViewSharedPtr & rView)410cdf0e10cSrcweir void SlideChangeBase::viewRemoved( const UnoViewSharedPtr& rView )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir     // we're a one-shot activity, and already finished
413cdf0e10cSrcweir     if( mbFinished )
414cdf0e10cSrcweir         return;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     // erase corresponding entry from maViewData
417cdf0e10cSrcweir     maViewData.erase(
418cdf0e10cSrcweir         std::remove_if(
419cdf0e10cSrcweir             maViewData.begin(),
420cdf0e10cSrcweir             maViewData.end(),
421cdf0e10cSrcweir             boost::bind(
422cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
423cdf0e10cSrcweir                 rView,
424cdf0e10cSrcweir                 // select view:
425cdf0e10cSrcweir                 boost::bind( &ViewEntry::getView, _1 ))),
426cdf0e10cSrcweir         maViewData.end() );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
viewChanged(const UnoViewSharedPtr & rView)429cdf0e10cSrcweir void SlideChangeBase::viewChanged( const UnoViewSharedPtr& rView )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir     // we're a one-shot activity, and already finished
432cdf0e10cSrcweir     if( mbFinished )
433cdf0e10cSrcweir         return;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     // find entry corresponding to modified view
436cdf0e10cSrcweir     ViewsVecT::iterator aModifiedEntry(
437cdf0e10cSrcweir         std::find_if(
438cdf0e10cSrcweir             maViewData.begin(),
439cdf0e10cSrcweir             maViewData.end(),
440cdf0e10cSrcweir             boost::bind(
441cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
442cdf0e10cSrcweir                 rView,
443cdf0e10cSrcweir                 // select view:
444cdf0e10cSrcweir                 boost::bind( &ViewEntry::getView, _1 ) )));
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     OSL_ASSERT( aModifiedEntry != maViewData.end() );
447cdf0e10cSrcweir     if( aModifiedEntry == maViewData.end() )
448cdf0e10cSrcweir         return;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     // clear stale info (both bitmaps and sprites prolly need a
451cdf0e10cSrcweir     // resize)
452cdf0e10cSrcweir     clearViewEntry( *aModifiedEntry );
453cdf0e10cSrcweir     addSprites( *aModifiedEntry );
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
viewsChanged()456cdf0e10cSrcweir void SlideChangeBase::viewsChanged()
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     // we're a one-shot activity, and already finished
459cdf0e10cSrcweir     if( mbFinished )
460cdf0e10cSrcweir         return;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     ViewsVecT::iterator       aIter( maViewData.begin() );
463cdf0e10cSrcweir     ViewsVecT::iterator const aEnd ( maViewData.end() );
464cdf0e10cSrcweir     while( aIter != aEnd )
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         // clear stale info (both bitmaps and sprites prolly need a
467cdf0e10cSrcweir         // resize)
468cdf0e10cSrcweir         clearViewEntry( *aIter );
469cdf0e10cSrcweir         addSprites( *aIter );
470cdf0e10cSrcweir 
471cdf0e10cSrcweir         ++aIter;
472cdf0e10cSrcweir     }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir 
createSprite(UnoViewSharedPtr const & pView,basegfx::B2DSize const & rSpriteSize,double nPrio) const475cdf0e10cSrcweir cppcanvas::CustomSpriteSharedPtr SlideChangeBase::createSprite(
476cdf0e10cSrcweir     UnoViewSharedPtr const & pView,
477cdf0e10cSrcweir     basegfx::B2DSize const & rSpriteSize,
478cdf0e10cSrcweir     double                   nPrio ) const
479cdf0e10cSrcweir {
480cdf0e10cSrcweir     // TODO(P2): change to bitmapsprite once that's working
481cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr pSprite(
482cdf0e10cSrcweir         pView->createSprite( rSpriteSize,
483cdf0e10cSrcweir                              nPrio ));
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     // alpha default is 0.0, which seems to be
486cdf0e10cSrcweir     // a bad idea when viewing content...
487cdf0e10cSrcweir     pSprite->setAlpha( 1.0 );
488cdf0e10cSrcweir     if (mbSpritesVisible)
489cdf0e10cSrcweir         pSprite->show();
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     return pSprite;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
addSprites(ViewEntry & rEntry)494cdf0e10cSrcweir void SlideChangeBase::addSprites( ViewEntry& rEntry )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir     if( mbCreateLeavingSprites && maLeavingSlide )
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         // create leaving sprite:
499cdf0e10cSrcweir         const basegfx::B2ISize leavingSlideSizePixel(
500cdf0e10cSrcweir             getLeavingBitmap( rEntry )->getSize() );
501cdf0e10cSrcweir 
502cdf0e10cSrcweir         rEntry.mpOutSprite = createSprite( rEntry.mpView,
503cdf0e10cSrcweir                                            leavingSlideSizePixel,
504cdf0e10cSrcweir                                            100 );
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir     if( mbCreateEnteringSprites )
508cdf0e10cSrcweir     {
509cdf0e10cSrcweir         // create entering sprite:
510cdf0e10cSrcweir         const basegfx::B2ISize enteringSlideSizePixel(
511cdf0e10cSrcweir             getSlideSizePixel( mpEnteringSlide->getSlideSize(),
512cdf0e10cSrcweir                                rEntry.mpView ));
513cdf0e10cSrcweir 
514cdf0e10cSrcweir         rEntry.mpInSprite = createSprite( rEntry.mpView,
515cdf0e10cSrcweir                                           enteringSlideSizePixel,
516cdf0e10cSrcweir                                           101 );
517cdf0e10cSrcweir     }
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
clearViewEntry(ViewEntry & rEntry)520cdf0e10cSrcweir void SlideChangeBase::clearViewEntry( ViewEntry& rEntry )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     // clear stale info (both bitmaps and sprites prolly need a
523cdf0e10cSrcweir     // resize)
524cdf0e10cSrcweir     rEntry.mpEnteringBitmap.reset();
525cdf0e10cSrcweir     rEntry.mpLeavingBitmap.reset();
526cdf0e10cSrcweir     rEntry.mpInSprite.reset();
527cdf0e10cSrcweir     rEntry.mpOutSprite.reset();
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir } // namespace internal
531cdf0e10cSrcweir } // namespace presentation
532