1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cppcanvas/customsprite.hxx>
25 #include <basegfx/point/b2dpoint.hxx>
26 #include <basegfx/vector/b2dsize.hxx>
27 #include <basegfx/vector/b2dvector.hxx>
29 #include <com/sun/star/rendering/XCanvas.hpp>
30 #include <com/sun/star/presentation/XSlideShowView.hpp>
31 #include <comphelper/diagnose_ex.hxx>
33 #include "waitsymbol.hxx"
34 #include <eventmultiplexer.hxx>
40 using namespace com::sun::star
;
42 namespace slideshow::internal
{
44 const sal_Int32 LEFT_BORDER_SPACE
= 10;
45 const sal_Int32 LOWER_BORDER_SPACE
= 10;
47 WaitSymbolSharedPtr
WaitSymbol::create( const uno::Reference
<rendering::XBitmap
>& xBitmap
,
48 ScreenUpdater
& rScreenUpdater
,
49 EventMultiplexer
& rEventMultiplexer
,
50 const UnoViewContainer
& rViewContainer
)
52 WaitSymbolSharedPtr
pRet(
53 new WaitSymbol( xBitmap
,
57 rEventMultiplexer
.addViewHandler( pRet
);
62 WaitSymbol::WaitSymbol( uno::Reference
<rendering::XBitmap
> xBitmap
,
63 ScreenUpdater
& rScreenUpdater
,
64 const UnoViewContainer
& rViewContainer
) :
65 mxBitmap(std::move(xBitmap
)),
67 mrScreenUpdater( rScreenUpdater
),
70 for( const auto& pView
: rViewContainer
)
74 void WaitSymbol::setVisible( const bool bVisible
)
76 if( mbVisible
== bVisible
)
81 for( const auto& rView
: maViews
)
92 // sprites changed, need a screen update for this frame.
93 mrScreenUpdater
.requestImmediateUpdate();
96 basegfx::B2DPoint
WaitSymbol::calcSpritePos(
97 UnoViewSharedPtr
const & rView
) const
99 const awt::Rectangle
aViewArea( rView
->getUnoView()->getCanvasArea() );
100 return basegfx::B2DPoint(
101 aViewArea
.X
+ std::min
<sal_Int32
>( aViewArea
.Width
, LEFT_BORDER_SPACE
),
102 aViewArea
.X
+ std::max
<sal_Int32
>( 0,
104 - mxBitmap
->getSize().Height
105 - LOWER_BORDER_SPACE
) );
108 void WaitSymbol::viewAdded( const UnoViewSharedPtr
& rView
)
110 cppcanvas::CustomSpriteSharedPtr sprite
;
114 const geometry::IntegerSize2D
spriteSize( mxBitmap
->getSize() );
115 sprite
= rView
->createSprite( basegfx::B2DSize( spriteSize
.Width
,
117 1000.0 ); // sprite should be in front of all
119 rendering::ViewState viewState
;
120 canvas::tools::initViewState( viewState
);
121 rendering::RenderState renderState
;
122 canvas::tools::initRenderState( renderState
);
123 sprite
->getContentCanvas()->getUNOCanvas()->drawBitmap(
124 mxBitmap
, viewState
, renderState
);
126 sprite
->setAlpha( 0.9 );
127 sprite
->movePixel( calcSpritePos( rView
) );
131 catch( uno::Exception
& )
133 TOOLS_WARN_EXCEPTION( "slideshow", "" );
136 maViews
.emplace_back( rView
, sprite
);
139 void WaitSymbol::viewRemoved( const UnoViewSharedPtr
& rView
)
144 ( const ViewsVecT::value_type
& cp
)
145 { return rView
== cp
.first
; } );
148 void WaitSymbol::viewChanged( const UnoViewSharedPtr
& rView
)
150 // find entry corresponding to modified view
151 ViewsVecT::iterator
aModifiedEntry(
156 ( const ViewsVecT::value_type
& cp
)
157 { return rView
== cp
.first
; } ) );
159 OSL_ASSERT( aModifiedEntry
!= maViews
.end() );
160 if( aModifiedEntry
== maViews
.end() )
163 if( aModifiedEntry
->second
)
164 aModifiedEntry
->second
->movePixel(
165 calcSpritePos(aModifiedEntry
->first
) );
168 void WaitSymbol::viewsChanged()
170 // reposition sprites on all views
171 for( const auto& rView
: maViews
)
174 rView
.second
->movePixel(
175 calcSpritePos( rView
.first
) );
179 } // namespace slideshow::internal
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */