fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / pointersymbol.cxx
blob20dd121ad877f2bf3621213c4d3d354652e9ff2c
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 <boost/current_function.hpp>
22 #include <canvas/canvastools.hxx>
24 #include <comphelper/anytostring.hxx>
25 #include <cppuhelper/exc_hlp.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>
33 #include "pointersymbol.hxx"
34 #include "eventmultiplexer.hxx"
36 #include <o3tl/compat_functional.hxx>
37 #include <algorithm>
40 using namespace com::sun::star;
42 namespace slideshow {
43 namespace internal {
45 PointerSymbolSharedPtr PointerSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
46 ScreenUpdater& rScreenUpdater,
47 EventMultiplexer& rEventMultiplexer,
48 const UnoViewContainer& rViewContainer )
50 PointerSymbolSharedPtr pRet(
51 new PointerSymbol( xBitmap,
52 rScreenUpdater,
53 rViewContainer ));
55 rEventMultiplexer.addViewHandler( pRet );
57 return pRet;
60 PointerSymbol::PointerSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
61 ScreenUpdater& rScreenUpdater,
62 const UnoViewContainer& rViewContainer ) :
63 mxBitmap(xBitmap),
64 maViews(),
65 mrScreenUpdater( rScreenUpdater ),
66 maPos(),
67 mbVisible(false)
69 std::for_each( rViewContainer.begin(),
70 rViewContainer.end(),
71 boost::bind( &PointerSymbol::viewAdded,
72 this,
73 _1 ));
76 void PointerSymbol::setVisible( const bool bVisible )
78 if( mbVisible != bVisible )
80 mbVisible = bVisible;
82 ViewsVecT::const_iterator aIter( maViews.begin() );
83 ViewsVecT::const_iterator const aEnd ( maViews.end() );
84 while( aIter != aEnd )
86 if( aIter->second )
88 if( bVisible )
89 aIter->second->show();
90 else
91 aIter->second->hide();
94 ++aIter;
97 // sprites changed, need a screen update for this frame.
98 mrScreenUpdater.requestImmediateUpdate();
102 basegfx::B2DPoint PointerSymbol::calcSpritePos(UnoViewSharedPtr const & rView) const
104 const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
105 const geometry::IntegerSize2D realTranslationOffset ( rView->getTranslationOffset() );
107 return basegfx::B2DPoint(
108 realTranslationOffset.Width + ((aViewArea.Width - aViewArea.X) - 2 * realTranslationOffset.Width) * maPos.X,
109 realTranslationOffset.Height + ((aViewArea.Height - aViewArea.Y) - 2 * realTranslationOffset.Height) * maPos.Y);
112 void PointerSymbol::viewAdded( const UnoViewSharedPtr& rView )
114 cppcanvas::CustomSpriteSharedPtr sprite;
118 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
119 sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
120 spriteSize.Height ),
121 1000.0 ); // sprite should be in front of all
122 // other sprites
123 rendering::ViewState viewState;
124 canvas::tools::initViewState( viewState );
125 rendering::RenderState renderState;
126 canvas::tools::initRenderState( renderState );
127 sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
128 mxBitmap, viewState, renderState );
130 sprite->setAlpha( 0.9 );
131 sprite->movePixel( calcSpritePos( rView ) );
132 if( mbVisible )
133 sprite->show();
135 catch( uno::Exception& )
137 OSL_FAIL( OUStringToOString(
138 comphelper::anyToString( cppu::getCaughtException() ),
139 RTL_TEXTENCODING_UTF8 ).getStr() );
142 maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
145 void PointerSymbol::viewRemoved( const UnoViewSharedPtr& rView )
147 maViews.erase(
148 std::remove_if(
149 maViews.begin(), maViews.end(),
150 boost::bind(
151 std::equal_to<UnoViewSharedPtr>(),
152 rView,
153 // select view:
154 boost::bind( o3tl::select1st<ViewsVecT::value_type>(), _1 ) ) ),
155 maViews.end() );
158 void PointerSymbol::viewChanged( const UnoViewSharedPtr& rView )
160 // find entry corresponding to modified view
161 ViewsVecT::iterator aModifiedEntry(
162 std::find_if(
163 maViews.begin(),
164 maViews.end(),
165 boost::bind(
166 std::equal_to<UnoViewSharedPtr>(),
167 rView,
168 // select view:
169 boost::bind( o3tl::select1st<ViewsVecT::value_type>(), _1 ))));
171 OSL_ASSERT( aModifiedEntry != maViews.end() );
172 if( aModifiedEntry == maViews.end() )
173 return;
175 if( aModifiedEntry->second )
176 aModifiedEntry->second->movePixel(
177 calcSpritePos(aModifiedEntry->first) );
180 void PointerSymbol::viewsChanged()
182 // reposition sprites on all views
183 ViewsVecT::const_iterator aIter( maViews.begin() );
184 ViewsVecT::const_iterator const aEnd ( maViews.end() );
185 while( aIter != aEnd )
187 if( aIter->second )
188 aIter->second->movePixel(
189 calcSpritePos( aIter->first ));
190 ++aIter;
194 void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos)
196 if( pos.X != maPos.X || pos.Y != maPos.Y )
198 maPos = pos;
200 // reposition sprites on all views
201 ViewsVecT::const_iterator aIter( maViews.begin() );
202 ViewsVecT::const_iterator const aEnd ( maViews.end() );
203 while( aIter != aEnd )
205 if( aIter->second )
207 aIter->second->movePixel(
208 calcSpritePos( aIter->first ));
209 mrScreenUpdater.notifyUpdate();
210 mrScreenUpdater.commitUpdates();
212 ++aIter;
217 } // namespace internal
218 } // namespace slideshow
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */