LibreOffice Module slideshow (master) 1
mediashape.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <com/sun/star/drawing/XShape.hpp>
22#include <o3tl/safeint.hxx>
23#include <osl/diagnose.h>
24
25#include "mediashape.hxx"
26#include "viewmediashape.hxx"
27#include "externalshapebase.hxx"
28#include <slideshowcontext.hxx>
29#include <shape.hxx>
30#include <tools.hxx>
31
32#include <algorithm>
33
34
35using namespace ::com::sun::star;
36
37
38namespace slideshow::internal
39{
40 namespace {
41
47 class MediaShape : public ExternalShapeBase
48 {
49 public:
59 MediaShape( const css::uno::Reference< css::drawing::XShape >& xShape,
60 double nPrio,
61 const SlideShowContext& rContext ); // throw ShapeLoadFailedException;
62
63 private:
64
65 // View layer methods
66
67
68 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer,
69 bool bRedrawLayer ) override;
70 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) override;
71 virtual void clearAllViewLayers() override;
72
73
74 // ExternalShapeBase methods
75
76
77 virtual bool implRender( const ::basegfx::B2DRange& rCurrBounds ) const override;
78 virtual void implViewChanged( const UnoViewSharedPtr& rView ) override;
79 virtual void implViewsChanged() override;
80 virtual bool implStartIntrinsicAnimation() override;
81 virtual bool implEndIntrinsicAnimation() override;
82 virtual void implPauseIntrinsicAnimation() override;
83 virtual bool implIsIntrinsicAnimationPlaying() const override;
84 virtual void implSetIntrinsicAnimationTime(double) override;
85 void implSetLooping(bool bLooping) override;
86
88 typedef ::std::vector< ViewMediaShapeSharedPtr > ViewMediaShapeVector;
89 ViewMediaShapeVector maViewMediaShapes;
91 };
92
93 }
94
95 MediaShape::MediaShape( const uno::Reference< drawing::XShape >& xShape,
96 double nPrio,
97 const SlideShowContext& rContext ) :
98 ExternalShapeBase( xShape, nPrio, rContext ),
100 mbIsPlaying(false)
101 {
102 }
103
104
105 void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
106 {
107 const ::basegfx::B2DRectangle& rBounds = getBounds();
108 // determine ViewMediaShape that needs update
109 for( const auto& pViewMediaShape : maViewMediaShapes )
110 if( pViewMediaShape->getViewLayer()->isOnView( rView ) )
111 pViewMediaShape->resize( rBounds );
112 }
113
114
115 void MediaShape::implViewsChanged()
116 {
117 const ::basegfx::B2DRectangle& rBounds = getBounds();
118 // resize all ViewShapes
119 for( const auto& pViewMediaShape : maViewMediaShapes )
120 pViewMediaShape->resize( rBounds );
121 }
122
123
124 void MediaShape::addViewLayer( const ViewLayerSharedPtr& rNewLayer,
125 bool bRedrawLayer )
126 {
127 maViewMediaShapes.push_back(
128 std::make_shared<ViewMediaShape>( rNewLayer,
129 getXShape(),
130 mxComponentContext ));
131
132 // push new size to view shape
133 maViewMediaShapes.back()->resize( getBounds() );
134
135 // render the Shape on the newly added ViewLayer
136 if( bRedrawLayer )
137 maViewMediaShapes.back()->render( getBounds() );
138 }
139
140
141 bool MediaShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
142 {
143 const ViewMediaShapeVector::iterator aEnd( maViewMediaShapes.end() );
144
145 OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
146 aEnd,
147 [&rLayer]
148 ( const ViewMediaShapeSharedPtr& pShape )
149 { return rLayer == pShape->getViewLayer(); } ) < 2,
150 "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
151
152 ViewMediaShapeVector::iterator aIter;
153
154 if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
155 aEnd,
156 [&rLayer]
157 ( const ViewMediaShapeSharedPtr& pShape )
158 { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
159 {
160 // view layer seemingly was not added, failed
161 return false;
162 }
163
164 // actually erase from container
165 maViewMediaShapes.erase( aIter, aEnd );
166
167 return true;
168 }
169
170
171 void MediaShape::clearAllViewLayers()
172 {
173 maViewMediaShapes.clear();
174 }
175
176
177 bool MediaShape::implRender( const ::basegfx::B2DRange& rCurrBounds ) const
178 {
179 // redraw all view shapes, by calling their update() method
180 if( o3tl::make_unsigned(::std::count_if( maViewMediaShapes.begin(),
181 maViewMediaShapes.end(),
182 [&rCurrBounds]
183 ( const ViewMediaShapeSharedPtr& pShape )
184 { return pShape->render( rCurrBounds ); } ))
185 != maViewMediaShapes.size() )
186 {
187 // at least one of the ViewShape::update() calls did return
188 // false - update failed on at least one ViewLayer
189 return false;
190 }
191
192 return true;
193 }
194
195
196 bool MediaShape::implStartIntrinsicAnimation()
197 {
198 for( const auto& pViewMediaShape : maViewMediaShapes )
199 pViewMediaShape->startMedia();
200
201 mbIsPlaying = true;
202
203 return true;
204 }
205
206
207 bool MediaShape::implEndIntrinsicAnimation()
208 {
209 for( const auto& pViewMediaShape : maViewMediaShapes )
210 pViewMediaShape->endMedia();
211
212 mbIsPlaying = false;
213
214 return true;
215 }
216
217
218 void MediaShape::implPauseIntrinsicAnimation()
219 {
220 for( const auto& pViewMediaShape : maViewMediaShapes )
221 pViewMediaShape->pauseMedia();
222
223 mbIsPlaying = false;
224 }
225
226
227 bool MediaShape::implIsIntrinsicAnimationPlaying() const
228 {
229 return mbIsPlaying;
230 }
231
232
233 void MediaShape::implSetIntrinsicAnimationTime(double fTime)
234 {
235 for( const auto& pViewMediaShape : maViewMediaShapes )
236 pViewMediaShape->setMediaTime( fTime );
237 }
238
239 void MediaShape::implSetLooping(bool bLooping)
240 {
241 for (const auto& pViewMediaShape : maViewMediaShapes)
242 {
243 pViewMediaShape->setLooping(bLooping);
244 }
245 }
246
249 double nPrio,
250 const SlideShowContext& rContext)
251 {
252 return std::make_shared<MediaShape>(xShape, nPrio, rContext);
253 }
254
255}
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbIsPlaying
Definition: mediashape.cxx:90
ViewMediaShapeVector maViewMediaShapes
Definition: mediashape.cxx:89
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
ShapeSharedPtr createMediaShape(const uno::Reference< drawing::XShape > &xShape, double nPrio, const SlideShowContext &rContext)
Definition: mediashape.cxx:247
std::shared_ptr< ViewLayer > ViewLayerSharedPtr
Definition: viewlayer.hxx:168
::std::shared_ptr< ViewMediaShape > ViewMediaShapeSharedPtr
::std::shared_ptr< Shape > ShapeSharedPtr
std::shared_ptr< UnoView > UnoViewSharedPtr
Common arguments for slideshow objects.