LibreOffice Module slideshow (master) 1
pointersymbol.cxx
Go to the documentation of this file.
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
22
24
27
28#include <com/sun/star/rendering/XCanvas.hpp>
29#include <com/sun/star/presentation/XSlideShowView.hpp>
31
32#include "pointersymbol.hxx"
33#include <eventmultiplexer.hxx>
34
35#include <algorithm>
36#include <utility>
37
38
39using namespace com::sun::star;
40
41namespace slideshow::internal {
42
44 ScreenUpdater& rScreenUpdater,
45 EventMultiplexer& rEventMultiplexer,
46 const UnoViewContainer& rViewContainer )
47{
49 new PointerSymbol( xBitmap,
50 rScreenUpdater,
51 rViewContainer ));
52
53 rEventMultiplexer.addViewHandler( pRet );
54
55 return pRet;
56}
57
59 ScreenUpdater& rScreenUpdater,
60 const UnoViewContainer& rViewContainer ) :
61 mxBitmap(std::move(xBitmap)),
62 maViews(),
63 mrScreenUpdater( rScreenUpdater ),
64 maPos(),
65 mbVisible(false)
66{
67 for( const auto& rView : rViewContainer )
68 viewAdded( rView );
69}
70
71void PointerSymbol::setVisible( const bool bVisible )
72{
73 if( mbVisible == bVisible )
74 return;
75
77
78 for( const auto& rView : maViews )
79 {
80 if( rView.second )
81 {
82 if( bVisible )
83 rView.second->show();
84 else
85 rView.second->hide();
86 }
87 }
88
89 // sprites changed, need a screen update for this frame.
91}
92
94{
95 const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
96 const geometry::IntegerSize2D realTranslationOffset ( rView->getTranslationOffset() );
97
98 return basegfx::B2DPoint(
99 realTranslationOffset.Width + (aViewArea.Width * maPos.X),
100 realTranslationOffset.Height + (aViewArea.Height * maPos.Y));
101}
102
104{
106
107 try
108 {
109 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
110 sprite = rView->createSprite( basegfx::B2DSize( 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 );
120
121 sprite->setAlpha( 0.9 );
122 sprite->movePixel( calcSpritePos( rView ) );
123 if( mbVisible )
124 sprite->show();
125 }
126 catch( uno::Exception& )
127 {
128 TOOLS_WARN_EXCEPTION( "slideshow", "" );
129 }
130
131 maViews.emplace_back( rView, sprite );
132}
133
135{
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() );
143}
144
146{
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; } ) );
155
156 OSL_ASSERT( aModifiedEntry != maViews.end() );
157 if( aModifiedEntry == maViews.end() )
158 return;
159
160 if( aModifiedEntry->second )
161 aModifiedEntry->second->movePixel(
162 calcSpritePos(aModifiedEntry->first) );
163}
164
166{
167 // reposition sprites on all views
168 for( const auto& rView : maViews )
169 {
170 if( rView.second )
171 rView.second->movePixel(
172 calcSpritePos( rView.first ) );
173 }
174}
175
176void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos)
177{
178 if( pos.X == maPos.X && pos.Y == maPos.Y )
179 return;
180
181 maPos = pos;
182
183 // reposition sprites on all views
184 for( const auto& rView : maViews )
185 {
186 if( rView.second )
187 {
188 rView.second->movePixel(
189 calcSpritePos( rView.first ) );
192 }
193 }
194}
195
196} // namespace slideshow::internal
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class multiplexes user-activated and slide-show global events.
void addViewHandler(const ViewEventHandlerWeakPtr &rHandler)
Register an event handler that will be called when views are changed.
void setVisible(const bool bVisible)
Use this method to update the pointer's position.
virtual void viewAdded(const UnoViewSharedPtr &rView) override
Notify new view.
virtual void viewChanged(const UnoViewSharedPtr &rView) override
Notify changed view.
static PointerSymbolSharedPtr create(const css::uno::Reference< css::rendering::XBitmap > &xBitmap, ScreenUpdater &rScreenUpdater, EventMultiplexer &rEventMultiplexer, const UnoViewContainer &rViewContainer)
::basegfx::B2DPoint calcSpritePos(UnoViewSharedPtr const &rView) const
PointerSymbol(css::uno::Reference< css::rendering::XBitmap > xBitmap, ScreenUpdater &rScreenUpdater, const UnoViewContainer &rViewContainer)
css::uno::Reference< css::rendering::XBitmap > mxBitmap
css::geometry::RealPoint2D maPos
virtual void viewRemoved(const UnoViewSharedPtr &rView) override
Notify removed view.
virtual void viewsChanged() override
Notify that all views changed.
void notifyUpdate()
Notify screen update.
void commitUpdates()
Commits collected update actions.
VclPtr< VirtualDevice > mxBitmap
#define TOOLS_WARN_EXCEPTION(area, stream)
rendering::RenderState & initRenderState(rendering::RenderState &renderState)
rendering::ViewState & initViewState(rendering::ViewState &viewState)
std::shared_ptr< ::cppcanvas::CustomSprite > CustomSpriteSharedPtr
std::shared_ptr< class PointerSymbol > PointerSymbolSharedPtr
std::shared_ptr< UnoView > UnoViewSharedPtr
bool mbVisible
bool bVisible
size_t pos