LCOV - code coverage report
Current view: top level - slideshow/source/engine - pointersymbol.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 77 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <boost/current_function.hpp>
      22             : #include <canvas/canvastools.hxx>
      23             : 
      24             : #include <comphelper/anytostring.hxx>
      25             : #include <cppuhelper/exc_hlp.hxx>
      26             : 
      27             : #include <basegfx/point/b2dpoint.hxx>
      28             : #include <basegfx/vector/b2dvector.hxx>
      29             : 
      30             : #include <com/sun/star/rendering/XCanvas.hpp>
      31             : #include <com/sun/star/presentation/XSlideShowView.hpp>
      32             : 
      33             : #include "pointersymbol.hxx"
      34             : #include "eventmultiplexer.hxx"
      35             : 
      36             : #include <o3tl/compat_functional.hxx>
      37             : #include <algorithm>
      38             : 
      39             : 
      40             : using namespace com::sun::star;
      41             : 
      42             : namespace slideshow {
      43             : namespace internal {
      44             : 
      45           0 : PointerSymbolSharedPtr PointerSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
      46             :                                               ScreenUpdater&                            rScreenUpdater,
      47             :                                               EventMultiplexer&                         rEventMultiplexer,
      48             :                                               const UnoViewContainer&                   rViewContainer )
      49             : {
      50             :     PointerSymbolSharedPtr pRet(
      51             :         new PointerSymbol( xBitmap,
      52             :                            rScreenUpdater,
      53           0 :                            rViewContainer ));
      54             : 
      55           0 :     rEventMultiplexer.addViewHandler( pRet );
      56             : 
      57           0 :     return pRet;
      58             : }
      59             : 
      60           0 : 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           0 :     mbVisible(false)
      68             : {
      69             :     std::for_each( rViewContainer.begin(),
      70             :                    rViewContainer.end(),
      71             :                    boost::bind( &PointerSymbol::viewAdded,
      72             :                                 this,
      73           0 :                                 _1 ));
      74           0 : }
      75             : 
      76           0 : void PointerSymbol::setVisible( const bool bVisible )
      77             : {
      78           0 :     if( mbVisible != bVisible )
      79             :     {
      80           0 :         mbVisible = bVisible;
      81             : 
      82           0 :         ViewsVecT::const_iterator       aIter( maViews.begin() );
      83           0 :         ViewsVecT::const_iterator const aEnd ( maViews.end() );
      84           0 :         while( aIter != aEnd )
      85             :         {
      86           0 :             if( aIter->second )
      87             :             {
      88           0 :                 if( bVisible )
      89           0 :                     aIter->second->show();
      90             :                 else
      91           0 :                     aIter->second->hide();
      92             :             }
      93             : 
      94           0 :             ++aIter;
      95             :         }
      96             : 
      97             :         // sprites changed, need a screen update for this frame.
      98           0 :         mrScreenUpdater.requestImmediateUpdate();
      99             :     }
     100           0 : }
     101             : 
     102           0 : basegfx::B2DPoint PointerSymbol::calcSpritePos(UnoViewSharedPtr const & rView) const
     103             : {
     104           0 :     const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
     105           0 :     const geometry::IntegerSize2D realTranslationOffset ( rView->getTranslationOffset() );
     106             : 
     107             :     return basegfx::B2DPoint(
     108           0 :         realTranslationOffset.Width + ((aViewArea.Width - aViewArea.X) - 2 * realTranslationOffset.Width) * maPos.X,
     109           0 :         realTranslationOffset.Height + ((aViewArea.Height - aViewArea.Y) - 2 * realTranslationOffset.Height) * maPos.Y);
     110             : }
     111             : 
     112           0 : void PointerSymbol::viewAdded( const UnoViewSharedPtr& rView )
     113             : {
     114           0 :     cppcanvas::CustomSpriteSharedPtr sprite;
     115             : 
     116             :     try
     117             :     {
     118           0 :         const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
     119           0 :         sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
     120             :                                                           spriteSize.Height ),
     121           0 :                                       1000.0 ); // sprite should be in front of all
     122             :                                                 // other sprites
     123           0 :         rendering::ViewState viewState;
     124           0 :         canvas::tools::initViewState( viewState );
     125           0 :         rendering::RenderState renderState;
     126           0 :         canvas::tools::initRenderState( renderState );
     127           0 :         sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
     128           0 :             mxBitmap, viewState, renderState );
     129             : 
     130           0 :         sprite->setAlpha( 0.9 );
     131           0 :         sprite->movePixel( calcSpritePos( rView ) );
     132           0 :         if( mbVisible )
     133           0 :             sprite->show();
     134             :     }
     135           0 :     catch( uno::Exception& )
     136             :     {
     137             :         OSL_FAIL( OUStringToOString(
     138             :                         comphelper::anyToString( cppu::getCaughtException() ),
     139             :                         RTL_TEXTENCODING_UTF8 ).getStr() );
     140             :     }
     141             : 
     142           0 :     maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
     143           0 : }
     144             : 
     145           0 : void PointerSymbol::viewRemoved( const UnoViewSharedPtr& rView )
     146             : {
     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           0 :         maViews.end() );
     156           0 : }
     157             : 
     158           0 : void PointerSymbol::viewChanged( const UnoViewSharedPtr& rView )
     159             : {
     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           0 :                 boost::bind( o3tl::select1st<ViewsVecT::value_type>(), _1 ))));
     170             : 
     171             :     OSL_ASSERT( aModifiedEntry != maViews.end() );
     172           0 :     if( aModifiedEntry == maViews.end() )
     173           0 :         return;
     174             : 
     175           0 :     if( aModifiedEntry->second )
     176           0 :         aModifiedEntry->second->movePixel(
     177           0 :             calcSpritePos(aModifiedEntry->first) );
     178             : }
     179             : 
     180           0 : void PointerSymbol::viewsChanged()
     181             : {
     182             :     // reposition sprites on all views
     183           0 :     ViewsVecT::const_iterator       aIter( maViews.begin() );
     184           0 :     ViewsVecT::const_iterator const aEnd ( maViews.end() );
     185           0 :     while( aIter != aEnd )
     186             :     {
     187           0 :         if( aIter->second )
     188           0 :             aIter->second->movePixel(
     189           0 :                 calcSpritePos( aIter->first ));
     190           0 :         ++aIter;
     191             :     }
     192           0 : }
     193             : 
     194           0 : void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos)
     195             : {
     196           0 :     if( pos.X != maPos.X || pos.Y != maPos.Y )
     197             :     {
     198           0 :         maPos = pos;
     199             : 
     200             :         // reposition sprites on all views
     201           0 :         ViewsVecT::const_iterator       aIter( maViews.begin() );
     202           0 :         ViewsVecT::const_iterator const aEnd ( maViews.end() );
     203           0 :         while( aIter != aEnd )
     204             :         {
     205           0 :             if( aIter->second )
     206             :             {
     207           0 :                 aIter->second->movePixel(
     208           0 :                 calcSpritePos( aIter->first ));
     209           0 :                 mrScreenUpdater.notifyUpdate();
     210           0 :                 mrScreenUpdater.commitUpdates();
     211             :             }
     212           0 :             ++aIter;
     213             :         }
     214             :     }
     215           0 : }
     216             : 
     217             : } // namespace internal
     218           0 : } // namespace slideshow
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10