Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / pointersymbol.cxx
blob14c5bdea0b0823df4677d17b281357b73fceb611
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>
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>
35 #include <algorithm>
38 using namespace com::sun::star;
40 namespace slideshow {
41 namespace internal {
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,
50 rScreenUpdater,
51 rViewContainer ));
53 rEventMultiplexer.addViewHandler( pRet );
55 return pRet;
58 PointerSymbol::PointerSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
59 ScreenUpdater& rScreenUpdater,
60 const UnoViewContainer& rViewContainer ) :
61 mxBitmap(xBitmap),
62 maViews(),
63 mrScreenUpdater( rScreenUpdater ),
64 maPos(),
65 mbVisible(false)
67 for( const auto& rView : rViewContainer )
68 viewAdded( rView );
71 void PointerSymbol::setVisible( const bool bVisible )
73 if( mbVisible != bVisible )
75 mbVisible = bVisible;
77 for( const auto& rView : maViews )
79 if( rView.second )
81 if( bVisible )
82 rView.second->show();
83 else
84 rView.second->hide();
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,
111 spriteSize.Height ),
112 1000.0 ); // sprite should be in front of all
113 // other sprites
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 ) );
123 if( mbVisible )
124 sprite->show();
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 )
136 maViews.erase(
137 std::remove_if(
138 maViews.begin(), maViews.end(),
139 [&rView]
140 ( const ViewsVecT::value_type& cp )
141 { return rView == cp.first; } ),
142 maViews.end() );
145 void PointerSymbol::viewChanged( const UnoViewSharedPtr& rView )
147 // find entry corresponding to modified view
148 ViewsVecT::iterator aModifiedEntry(
149 std::find_if(
150 maViews.begin(),
151 maViews.end(),
152 [&rView]
153 ( const ViewsVecT::value_type& cp )
154 { return rView == cp.first; } ) );
156 OSL_ASSERT( aModifiedEntry != maViews.end() );
157 if( aModifiedEntry == maViews.end() )
158 return;
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 )
170 if( rView.second )
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 )
180 maPos = pos;
182 // reposition sprites on all views
183 for( const auto& rView : maViews )
185 if( rView.second )
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: */