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 <comphelper/anytostring.hxx>
24 #include <cppuhelper/exc_hlp.hxx>
26 #include <basegfx/point/b2dpoint.hxx>
27 #include <basegfx/vector/b2dvector.hxx>
29 #include <com/sun/star/rendering/XCanvas.hpp>
30 #include <com/sun/star/presentation/XSlideShowView.hpp>
32 #include "pointersymbol.hxx"
33 #include <eventmultiplexer.hxx>
38 using namespace com::sun::star
;
43 PointerSymbolSharedPtr
PointerSymbol::create( const uno::Reference
<rendering::XBitmap
>& xBitmap
,
44 ScreenUpdater
& rScreenUpdater
,
45 EventMultiplexer
& rEventMultiplexer
,
46 const UnoViewContainer
& rViewContainer
)
48 PointerSymbolSharedPtr
pRet(
49 new PointerSymbol( xBitmap
,
53 rEventMultiplexer
.addViewHandler( pRet
);
58 PointerSymbol::PointerSymbol( uno::Reference
<rendering::XBitmap
> const & xBitmap
,
59 ScreenUpdater
& rScreenUpdater
,
60 const UnoViewContainer
& rViewContainer
) :
63 mrScreenUpdater( rScreenUpdater
),
67 for( const auto& rView
: rViewContainer
)
71 void PointerSymbol::setVisible( const bool bVisible
)
73 if( mbVisible
!= bVisible
)
77 for( const auto& rView
: maViews
)
88 // sprites changed, need a screen update for this frame.
89 mrScreenUpdater
.requestImmediateUpdate();
93 basegfx::B2DPoint
PointerSymbol::calcSpritePos(UnoViewSharedPtr
const & rView
) const
95 const awt::Rectangle
aViewArea( rView
->getUnoView()->getCanvasArea() );
96 const geometry::IntegerSize2D
realTranslationOffset ( rView
->getTranslationOffset() );
98 return basegfx::B2DPoint(
99 realTranslationOffset
.Width
+ ((aViewArea
.Width
- aViewArea
.X
) - 2 * realTranslationOffset
.Width
) * maPos
.X
,
100 realTranslationOffset
.Height
+ ((aViewArea
.Height
- aViewArea
.Y
) - 2 * realTranslationOffset
.Height
) * maPos
.Y
);
103 void PointerSymbol::viewAdded( const UnoViewSharedPtr
& rView
)
105 cppcanvas::CustomSpriteSharedPtr sprite
;
109 const geometry::IntegerSize2D
spriteSize( mxBitmap
->getSize() );
110 sprite
= rView
->createSprite( basegfx::B2DVector( spriteSize
.Width
,
112 1000.0 ); // sprite should be in front of all
114 rendering::ViewState viewState
;
115 canvas::tools::initViewState( viewState
);
116 rendering::RenderState renderState
;
117 canvas::tools::initRenderState( renderState
);
118 sprite
->getContentCanvas()->getUNOCanvas()->drawBitmap(
119 mxBitmap
, viewState
, renderState
);
121 sprite
->setAlpha( 0.9 );
122 sprite
->movePixel( calcSpritePos( rView
) );
126 catch( uno::Exception
& )
128 SAL_WARN( "slideshow", comphelper::anyToString( cppu::getCaughtException() ) );
131 maViews
.emplace_back( rView
, sprite
);
134 void PointerSymbol::viewRemoved( const UnoViewSharedPtr
& rView
)
138 maViews
.begin(), maViews
.end(),
140 ( const ViewsVecT::value_type
& cp
)
141 { return rView
== cp
.first
; } ),
145 void PointerSymbol::viewChanged( const UnoViewSharedPtr
& rView
)
147 // find entry corresponding to modified view
148 ViewsVecT::iterator
aModifiedEntry(
153 ( const ViewsVecT::value_type
& cp
)
154 { return rView
== cp
.first
; } ) );
156 OSL_ASSERT( aModifiedEntry
!= maViews
.end() );
157 if( aModifiedEntry
== maViews
.end() )
160 if( aModifiedEntry
->second
)
161 aModifiedEntry
->second
->movePixel(
162 calcSpritePos(aModifiedEntry
->first
) );
165 void PointerSymbol::viewsChanged()
167 // reposition sprites on all views
168 for( const auto& rView
: maViews
)
171 rView
.second
->movePixel(
172 calcSpritePos( rView
.first
) );
176 void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos
)
178 if( pos
.X
!= maPos
.X
|| pos
.Y
!= maPos
.Y
)
182 // reposition sprites on all views
183 for( const auto& rView
: maViews
)
187 rView
.second
->movePixel(
188 calcSpritePos( rView
.first
) );
189 mrScreenUpdater
.notifyUpdate();
190 mrScreenUpdater
.commitUpdates();
196 } // namespace internal
197 } // namespace slideshow
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */