/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
@param rCanvas Canvas to create the clip polygon for
@param rUserSize The size of the view. Note that the returned clip will <em>always</em> clip to at least the rect defined herein.
@return the view clip polygon, in view coordinates, which is guaranteed to at least clip to the view size.
*/
basegfx::B2DPolyPolygon createClipPolygon( const basegfx::B2DPolyPolygon& rClip, const cppcanvas::CanvasSharedPtr& /*rCanvas*/, const basegfx::B2DSize& rUserSize )
{ // setup canvas clipping // =====================
/** Prepare given clip polygon to be stored as the current clip
Note that this is separate from createClipPolygon(), to allow SlideView implementations to store this intermediate result (createClipPolygon() has to be called every time the view size changes)
*/
basegfx::B2DPolyPolygon prepareClip( const basegfx::B2DPolyPolygon& rClip )
{
basegfx::B2DPolyPolygon aClip( rClip );
// set transformation to identity (->device pixel)
pCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
// #i42440# Fill the _full_ background in // black. Since we had to extend the bitmap by one // pixel, and the bitmap is initialized white, // depending on the slide content a one pixel wide // line will show to the bottom and the right. const ::basegfx::B2DPolygon aPoly(
::basegfx::utils::createPolygonFromRect(
basegfx::B2DRange(rArea)));
@param rLayerBounds Bound rect, in user space coordinates
@param rTransformation User space to device pixel transformation
@return the layer bounds in pixel, extended by one pixel to the right and bottom
*/
basegfx::B2IRange getLayerBoundsPixel( basegfx::B2DRange const& rLayerBounds,
basegfx::B2DHomMatrix const& rTransformation )
{
::basegfx::B2DRange aTmpRect = ::canvas::tools::calcTransformedRectBounds(
rLayerBounds,
rTransformation );
// #i42440# Returned layer size is one pixel too small, as // rendering happens one pixel to the right and below the // actual bound rect. return ::basegfx::B2IRange( ::basegfx::fround(aTmpRect.getMinX()),
::basegfx::fround(aTmpRect.getMinY()),
::basegfx::fround(aTmpRect.getMaxX()) + 1,
::basegfx::fround(aTmpRect.getMaxY()) + 1 );
}
/** Container class for sprites issued by a ViewLayer
This class handles the sprite prioritization issues, that are needed for layer sprites (e.g. the need to re-prioritize sprites when the layer changes prio).
*/ class LayerSpriteContainer
{ /** Max fill level of maSprites, before we try to prune it from deceased sprites
*/ enum{ SPRITE_ULLAGE=256 };
/** All sprites that have been issued by this container (pruned from time to time, for invalid references). This vector is kept sorted with increasing sprite priority.
*/
SpriteVector maSprites;
/// Priority of this layer, relative to other view layers
basegfx::B1DRange maLayerPrioRange;
double getSpritePriority( std::size_t nSpriteNum ) const
{ // divide the available layer range equally between all // sprites, assign upper bound of individual sprite range as // sprite prio (the layer itself gets assigned the lower bound // of sprite 0's individual range):
@param aBegin Iterator to the first entry to rescan
*/ void updateSprites()
{
SpriteVector aValidSprites;
// check all sprites for validity and set new priority for( constauto& rSprite : maSprites )
{
cppcanvas::CustomSpriteSharedPtr pCurrSprite( rSprite.mpSprite.lock() );
if( pCurrSprite )
{ // only copy still valid sprites over to the refreshed // sprite vector.
aValidSprites.push_back( rSprite );
// insert new sprite, such that vector stays sorted
SpriteVector::iterator aInsertPos(
maSprites.insert(
std::lower_bound( maSprites.begin(),
maSprites.end(),
aEntry ),
aEntry ));
const std::size_t nNumSprites( maSprites.size() ); if( nNumSprites > SPRITE_ULLAGE ||
maSprites.end() - aInsertPos > 1 )
{ // updateSprites() also updates all sprite prios
updateSprites();
} else
{ // added sprite to the end, and not too many sprites in // vector - perform optimized update (only need to set // prio). This basically caters for the common case of // iterated character animations, which generate lots of // sprites, all added to the end.
pSprite->setPriority(
getSpritePriority( nNumSprites-1 ));
}
}
void clear()
{
maSprites.clear();
}
};
/** This class provides layers for a slide view
Layers are used to render animations with the correct z order - because sprites are always in front of the static canvas background, shapes that must appear <em<before</em> an animation must also be displayed as a sprite.
Each layer has a priority assigned to it (valid range [0,1]), which also affects all sprites created for this specific layer - i.e. if the layer priority changes, the sprites change z order together with their parent.
*/ class SlideViewLayer : public ViewLayer
{ /// Smart container for all sprites issued by this layer mutable LayerSpriteContainer maSpriteContainer;
/// Bounds of this layer in user space coordinates
basegfx::B2DRange maLayerBounds;
/// Bounds of this layer in device pixel mutable basegfx::B2IRange maLayerBoundsPixel;
/// Current clip polygon in user coordinates
basegfx::B2DPolyPolygon maClip;
/// Current size of the view in user coordinates
basegfx::B2DSize maUserSize;
/// Current overall view transformation
basegfx::B2DHomMatrix maTransformation;
/// 'parent' canvas, this viewlayer is associated with const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas;
/** output surface (necessarily a sprite, won't otherwise be able to display anything <em>before</em> other sprites)
*/ mutable cppcanvas::CustomSpriteSharedPtr mpSprite;
/// actual output canvas retrieved from a sprite mutable cppcanvas::CanvasSharedPtr mpOutputCanvas;
/// ptr back to owning view. needed for isOnView() method
View const* const mpParentView;
public: /** Create a new layer
@param pCanvas Sprite canvas to create the layer on
// Add translation according to the origin of aTmpRect. Ignore the // translation when aTmpRect was not properly initialized. if ( ! aTmpRect.isEmpty())
{
offset.Width = basegfx::fround(aTmpRect.getMinX());
offset.Height = basegfx::fround(aTmpRect.getMinY());
} return offset;
}
virtual basegfx::B2DHomMatrix getTransformation() const override
{ // Offset given transformation by left, top border of given // range (after transformation through given transformation)
basegfx::B2DRectangle aTmpRect = canvas::tools::calcTransformedRectBounds(
maLayerBounds,
maTransformation );
// Add translation according to the origin of aTmpRect. Ignore the // translation when aTmpRect was not properly initialized. if ( ! aTmpRect.isEmpty())
{
aMatrix.translate( -std::round(aTmpRect.getMinX()),
-std::round(aTmpRect.getMinY()) );
}
// HACK: ensure at least 1x1 pixel size. clients might // need an actual canvas (e.g. for bound rect // calculations) without rendering anything. Better // solution: introduce something like a reference // canvas for ViewLayers, which is always available. if( maLayerBoundsPixel.isEmpty() )
maLayerBoundsPixel = basegfx::B2IRange(0,0,1,1);
This class implements the View interface, encapsulating <em>one</em> view a slideshow is displayed on.
*/ class SlideView : private cppu::BaseMutex, public SlideViewBase, public UnoView
{ public:
SlideView( const uno::Reference<presentation::XSlideShowView>& xView,
EventQueue& rEventQueue,
EventMultiplexer& rEventMultiplexer ); void updateCanvas();
// additionally, also de-register from XSlideShowView if (mxView.is())
{
mxView->removeTransformationChangedListener( this );
mxView->removePaintListener( this );
mxView.clear();
}
}
mpCanvas->clear(); // this is unnecessary, strictly speaking. but // it makes the SlideView behave exactly like a // sprite-based SlideViewLayer, because those // are created from scratch after a resize
void SlideView::setPriority( const basegfx::B1DRange& /*rRange*/ )
{
OSL_FAIL( "SlideView::setPriority() is a NOOP for slide view - " "content will always be shown in the background" );
}
// check all layers for validity, and retain only the live ones for( constauto& rView : maViewLayers )
{
std::shared_ptr< SlideViewLayer > xCurrLayer( rView.lock() );
if ( xCurrLayer )
{
aValidLayers.push_back( xCurrLayer );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.