Bump version to 6.4-15
[LibreOffice.git] / slideshow / source / engine / waitsymbol.cxx
blob4612262358f7cbb0a9f1b201c8b0bd756fee9d88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <canvas/canvastools.hxx>
23 #include <comphelper/anytostring.hxx>
24 #include <cppuhelper/exc_hlp.hxx>
25 #include <sal/log.hxx>
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/vector/b2dvector.hxx>
30 #include <com/sun/star/rendering/XCanvas.hpp>
31 #include <com/sun/star/presentation/XSlideShowView.hpp>
32 #include <tools/diagnose_ex.h>
34 #include "waitsymbol.hxx"
35 #include <eventmultiplexer.hxx>
37 #include <algorithm>
40 using namespace com::sun::star;
42 namespace slideshow {
43 namespace internal {
45 const sal_Int32 LEFT_BORDER_SPACE = 10;
46 const sal_Int32 LOWER_BORDER_SPACE = 10;
48 WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
49 ScreenUpdater& rScreenUpdater,
50 EventMultiplexer& rEventMultiplexer,
51 const UnoViewContainer& rViewContainer )
53 WaitSymbolSharedPtr pRet(
54 new WaitSymbol( xBitmap,
55 rScreenUpdater,
56 rViewContainer ));
58 rEventMultiplexer.addViewHandler( pRet );
60 return pRet;
63 WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
64 ScreenUpdater& rScreenUpdater,
65 const UnoViewContainer& rViewContainer ) :
66 mxBitmap(xBitmap),
67 maViews(),
68 mrScreenUpdater( rScreenUpdater ),
69 mbVisible(false)
71 for( const auto& pView : rViewContainer )
72 viewAdded( pView );
75 void WaitSymbol::setVisible( const bool bVisible )
77 if( mbVisible == bVisible )
78 return;
80 mbVisible = bVisible;
82 for( const auto& rView : maViews )
84 if( rView.second )
86 if( bVisible )
87 rView.second->show();
88 else
89 rView.second->hide();
93 // sprites changed, need a screen update for this frame.
94 mrScreenUpdater.requestImmediateUpdate();
97 basegfx::B2DPoint WaitSymbol::calcSpritePos(
98 UnoViewSharedPtr const & rView ) const
100 const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
101 return basegfx::B2DPoint(
102 aViewArea.X + std::min<sal_Int32>( aViewArea.Width, LEFT_BORDER_SPACE ),
103 aViewArea.X + std::max<sal_Int32>( 0,
104 aViewArea.Height
105 - mxBitmap->getSize().Height
106 - LOWER_BORDER_SPACE ) );
109 void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView )
111 cppcanvas::CustomSpriteSharedPtr sprite;
115 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
116 sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
117 spriteSize.Height ),
118 1000.0 ); // sprite should be in front of all
119 // other sprites
120 rendering::ViewState viewState;
121 canvas::tools::initViewState( viewState );
122 rendering::RenderState renderState;
123 canvas::tools::initRenderState( renderState );
124 sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
125 mxBitmap, viewState, renderState );
127 sprite->setAlpha( 0.9 );
128 sprite->movePixel( calcSpritePos( rView ) );
129 if( mbVisible )
130 sprite->show();
132 catch( uno::Exception& )
134 TOOLS_WARN_EXCEPTION( "slideshow", "" );
137 maViews.emplace_back( rView, sprite );
140 void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView )
142 maViews.erase(
143 std::remove_if(
144 maViews.begin(), maViews.end(),
145 [&rView]
146 ( const ViewsVecT::value_type& cp )
147 { return rView == cp.first; } ),
148 maViews.end() );
151 void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
153 // find entry corresponding to modified view
154 ViewsVecT::iterator aModifiedEntry(
155 std::find_if(
156 maViews.begin(),
157 maViews.end(),
158 [&rView]
159 ( const ViewsVecT::value_type& cp )
160 { return rView == cp.first; } ) );
162 OSL_ASSERT( aModifiedEntry != maViews.end() );
163 if( aModifiedEntry == maViews.end() )
164 return;
166 if( aModifiedEntry->second )
167 aModifiedEntry->second->movePixel(
168 calcSpritePos(aModifiedEntry->first) );
171 void WaitSymbol::viewsChanged()
173 // reposition sprites on all views
174 for( const auto& rView : maViews )
176 if( rView.second )
177 rView.second->movePixel(
178 calcSpritePos( rView.first ) );
182 } // namespace internal
183 } // namespace slideshow
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */