1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX
25 #define INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX
26 
27 #include <osl/mutex.hxx>
28 
29 #include "unoview.hxx"
30 #include "vieweventhandler.hxx"
31 #include "numberanimation.hxx"
32 #include "slide.hxx"
33 #include "screenupdater.hxx"
34 #include "soundplayer.hxx"
35 
36 #include <boost/enable_shared_from_this.hpp>
37 #include <boost/noncopyable.hpp>
38 #include <boost/optional.hpp>
39 
40 namespace cppcanvas
41 {
42     class Canvas;
43     class CustomSprite;
44 }
45 
46 namespace slideshow {
47 namespace internal {
48 
49 /** Base class for all slide change effects.
50 
51     This class provides the basic sprite and view handling
52     functionality.  Derived classes should normally only need to
53     implement the perform() method.
54 */
55 class SlideChangeBase : public ViewEventHandler,
56                         public NumberAnimation,
57                         public boost::enable_shared_from_this<SlideChangeBase>,
58                         private ::boost::noncopyable
59 {
60 public:
61     // NumberAnimation
62     virtual bool operator()( double x );
63     virtual double getUnderlyingValue() const;
64 
65     // Animation
66     virtual void prefetch( const AnimatableShapeSharedPtr&,
67                            const ShapeAttributeLayerSharedPtr& );
68     virtual void start( const AnimatableShapeSharedPtr&,
69                         const ShapeAttributeLayerSharedPtr& );
70     virtual void end();
71 
72     // ViewEventHandler
73     virtual void viewAdded( const UnoViewSharedPtr& rView );
74     virtual void viewRemoved( const UnoViewSharedPtr& rView );
75     virtual void viewChanged( const UnoViewSharedPtr& rView );
76     virtual void viewsChanged();
77 
78 protected:
79     /** Create a new SlideChanger, for the given leaving and
80         entering slides.
81     */
82     SlideChangeBase(
83         ::boost::optional<SlideSharedPtr> const & leavingSlide,
84         const SlideSharedPtr&                     pEnteringSlide,
85         const SoundPlayerSharedPtr&               pSoundPlayer,
86         const UnoViewContainer&                   rViewContainer,
87         ScreenUpdater&                            rScreenUpdater,
88         EventMultiplexer&                         rEventMultiplexer,
89         bool                                      bCreateLeavingSprites = true,
90         bool                                      bCreateEnteringSprites = true );
91 
92     /// Info on a per-view basis
93     struct ViewEntry
94     {
ViewEntryslideshow::internal::SlideChangeBase::ViewEntry95         ViewEntry() {}
96 
ViewEntryslideshow::internal::SlideChangeBase::ViewEntry97         explicit ViewEntry( const UnoViewSharedPtr& rView ) :
98             mpView( rView )
99         {
100         }
101 
102         /// The view this entry is for
103         UnoViewSharedPtr                              mpView;
104         /// outgoing slide sprite
105         boost::shared_ptr<cppcanvas::CustomSprite>    mpOutSprite;
106         /// incoming slide sprite
107         boost::shared_ptr<cppcanvas::CustomSprite>    mpInSprite;
108         /// outgoing slide bitmap
109         mutable SlideBitmapSharedPtr                  mpLeavingBitmap;
110         /// incoming slide bitmap
111         mutable SlideBitmapSharedPtr                  mpEnteringBitmap;
112 
113         // for algo access
getViewslideshow::internal::SlideChangeBase::ViewEntry114         const UnoViewSharedPtr& getView() const { return mpView; }
115     };
116 
117     typedef ::std::vector<ViewEntry> ViewsVecT;
118 
beginViews()119     ViewsVecT::const_iterator beginViews() { return maViewData.begin(); }
endViews()120     ViewsVecT::const_iterator endViews() { return maViewData.end(); }
121 
122     SlideBitmapSharedPtr getLeavingBitmap( const ViewEntry& rViewEntry ) const;
123     SlideBitmapSharedPtr getEnteringBitmap( const ViewEntry& rViewEntry ) const;
124 
125     SlideBitmapSharedPtr createBitmap( const UnoViewSharedPtr&                pView,
126                                        const boost::optional<SlideSharedPtr>& rSlide_ ) const;
127 
128     ::basegfx::B2ISize getEnteringSlideSizePixel( const UnoViewSharedPtr& pView ) const;
129     ::basegfx::B2ISize getLeavingSlideSizePixel( const UnoViewSharedPtr& pView ) const;
130 
131     void renderBitmap( SlideBitmapSharedPtr const&                 pSlideBitmap,
132                        boost::shared_ptr<cppcanvas::Canvas> const& pCanvas );
133 
134     /** Called on derived classes to implement actual slide change.
135 
136         This method is called with the sprite of the slide coming 'in'
137 
138         @param rSprite
139         Current sprite to operate on. This is the sprite of the
140         'entering' slide
141 
142         @param t
143         Current parameter value
144     */
145     virtual void performIn(
146         const boost::shared_ptr<cppcanvas::CustomSprite>&   rSprite,
147         const ViewEntry&                                    rViewEntry,
148         const boost::shared_ptr<cppcanvas::Canvas>&         rDestinationCanvas,
149         double                                              t );
150 
151     /** Called on derived classes to implement actual slide change.
152 
153         This method is called with the sprite of the slide moving 'out'
154 
155         @param rSprite
156         Current sprite to operate on. This is the sprite of the
157         'leaving' slide
158 
159         @param t
160         Current parameter value
161     */
162     virtual void performOut(
163         const boost::shared_ptr<cppcanvas::CustomSprite>& rSprite,
164         const ViewEntry&                                  rViewEntry,
165         const boost::shared_ptr<cppcanvas::Canvas>&       rDestinationCanvas,
166         double                                            t );
167 
getScreenUpdater() const168     ScreenUpdater& getScreenUpdater() const { return mrScreenUpdater; }
169 
170 private:
171 
172     boost::shared_ptr<cppcanvas::CustomSprite> createSprite(
173         UnoViewSharedPtr const &   pView,
174         ::basegfx::B2DSize const & rSpriteSize,
175         double                     nPrio ) const;
176 
177     void addSprites( ViewEntry& rEntry );
178     void clearViewEntry( ViewEntry& rEntry );
179 
180     ViewsVecT::iterator lookupView( UnoViewSharedPtr const & pView );
181     ViewsVecT::const_iterator lookupView( UnoViewSharedPtr const & pView ) const;
182 
183     SoundPlayerSharedPtr                mpSoundPlayer;
184 
185     EventMultiplexer&                   mrEventMultiplexer;
186     ScreenUpdater&                      mrScreenUpdater;
187 
188     ::boost::optional<SlideSharedPtr>   maLeavingSlide;
189     SlideSharedPtr                      mpEnteringSlide;
190 
191     ViewsVecT                           maViewData;
192     const UnoViewContainer&             mrViewContainer;
193 
194     const bool                          mbCreateLeavingSprites;
195     const bool                          mbCreateEnteringSprites;
196     bool                                mbSpritesVisible;
197     bool                                mbFinished;
198     bool                                mbPrefetched;
199 };
200 
201 } // namespace internal
202 } // namespace presentation
203 
204 #endif /* INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX */
205