1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 #include "combtransition.hxx"
28 namespace slideshow::internal
{
32 basegfx::B2DPolyPolygon
createClipPolygon(
33 const ::basegfx::B2DVector
& rDirection
,
34 const ::basegfx::B2DSize
& rSlideSize
,
35 int nNumStrips
, int nOffset
)
37 // create clip polygon in standard orientation (will later
38 // be rotated to match direction vector)
39 ::basegfx::B2DPolyPolygon aClipPoly
;
41 // create nNumStrips/2 vertical strips
42 for( int i
=nOffset
; i
<nNumStrips
; i
+=2 )
45 ::basegfx::utils::createPolygonFromRect(
46 ::basegfx::B2DRectangle( double(i
)/nNumStrips
, 0.0,
47 double(i
+1)/nNumStrips
, 1.0) ) );
51 // rotate polygons, such that the strips are parallel to
52 // the given direction vector
53 const ::basegfx::B2DVector
aUpVec(0.0, 1.0);
54 basegfx::B2DHomMatrix
aMatrix(basegfx::utils::createRotateAroundPoint(0.5, 0.5, aUpVec
.angle( rDirection
)));
56 // blow up clip polygon to slide size
57 aMatrix
.scale(rSlideSize
.getWidth(), rSlideSize
.getHeight());
59 aClipPoly
.transform( aMatrix
);
66 CombTransition::CombTransition(
67 std::optional
<SlideSharedPtr
> const & leavingSlide
,
68 const SlideSharedPtr
& pEnteringSlide
,
69 const SoundPlayerSharedPtr
& pSoundPlayer
,
70 const UnoViewContainer
& rViewContainer
,
71 ScreenUpdater
& rScreenUpdater
,
72 EventMultiplexer
& rEventMultiplexer
,
73 const ::basegfx::B2DVector
& rPushDirection
,
74 sal_Int32 nNumStripes
)
75 : SlideChangeBase( leavingSlide
, pEnteringSlide
, pSoundPlayer
,
76 rViewContainer
, rScreenUpdater
, rEventMultiplexer
,
77 false /* no leaving sprite */,
78 false /* no entering sprite */ ),
79 maPushDirectionUnit( rPushDirection
),
80 mnNumStripes( nNumStripes
)
84 void CombTransition::renderComb( double t
,
85 const ViewEntry
& rViewEntry
) const
87 const SlideBitmapSharedPtr xEnteringBitmap
= getEnteringBitmap(rViewEntry
);
88 const cppcanvas::CanvasSharedPtr pCanvas_
= rViewEntry
.mpView
->getCanvas();
90 if( !xEnteringBitmap
|| !pCanvas_
)
93 // calc bitmap offsets. The enter/leaving bitmaps are only
94 // as large as the actual slides. For scaled-down
95 // presentations, we have to move the left, top edge of
96 // those bitmaps to the actual position, governed by the
97 // given view transform. The aBitmapPosPixel local
98 // variable is already in device coordinate space
101 // TODO(F2): Properly respect clip here. Might have to be transformed, too.
102 const basegfx::B2DHomMatrix
viewTransform( rViewEntry
.mpView
->getTransformation() );
103 const basegfx::B2DPoint
pageOrigin( viewTransform
* basegfx::B2DPoint() );
105 // change transformation on cloned canvas to be in
107 cppcanvas::CanvasSharedPtr
pCanvas( pCanvas_
->clone() );
110 // TODO(Q2): Use basegfx bitmaps here
111 // TODO(F1): SlideBitmap is not fully portable between different canvases!
113 auto aSlideSizePixel
= getEnteringSlideSizePixel(rViewEntry
.mpView
);
114 const basegfx::B2DVector
enteringSizePixel(aSlideSizePixel
.getWidth(), aSlideSizePixel
.getHeight());
116 const basegfx::B2DVector
aPushDirection(
117 enteringSizePixel
* maPushDirectionUnit
);
118 const basegfx::B2DPolyPolygon aClipPolygon1
=
119 createClipPolygon( maPushDirectionUnit
,
120 basegfx::B2DSize(enteringSizePixel
.getX(), enteringSizePixel
.getY()),
122 const basegfx::B2DPolyPolygon aClipPolygon2
=
123 createClipPolygon( maPushDirectionUnit
,
124 basegfx::B2DSize(enteringSizePixel
.getX(), enteringSizePixel
.getY()),
127 SlideBitmapSharedPtr
const xLeavingBitmap
= getLeavingBitmap(rViewEntry
);
130 // render odd strips:
131 xLeavingBitmap
->clip( aClipPolygon1
);
132 // don't modify bitmap object (no move!):
133 p
= basegfx::B2DPoint( pageOrigin
+ (t
* aPushDirection
) );
134 pCanvas
->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p
.getX(), p
.getY()));
135 xLeavingBitmap
->draw( pCanvas
);
137 // render even strips:
138 xLeavingBitmap
->clip( aClipPolygon2
);
139 // don't modify bitmap object (no move!):
140 p
= basegfx::B2DPoint( pageOrigin
- (t
* aPushDirection
) );
141 pCanvas
->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p
.getX(), p
.getY()));
142 xLeavingBitmap
->draw( pCanvas
);
145 // TODO(Q2): Use basegfx bitmaps here
146 // TODO(F1): SlideBitmap is not fully portable between different canvases!
148 // render odd strips:
149 xEnteringBitmap
->clip( aClipPolygon1
);
150 // don't modify bitmap object (no move!):
151 p
= basegfx::B2DPoint( pageOrigin
+ ((t
- 1.0) * aPushDirection
) );
152 pCanvas
->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p
.getX(), p
.getY()));
153 xEnteringBitmap
->draw( pCanvas
);
155 // render even strips:
156 xEnteringBitmap
->clip( aClipPolygon2
);
157 // don't modify bitmap object (no move!):
158 p
= basegfx::B2DPoint( pageOrigin
+ ((1.0 - t
) * aPushDirection
) );
159 pCanvas
->setTransformation(basegfx::utils::createTranslateB2DHomMatrix(p
.getX(), p
.getY()));
160 xEnteringBitmap
->draw( pCanvas
);
163 bool CombTransition::operator()( double t
)
165 std::for_each( beginViews(),
167 [this, &t
]( const ViewEntry
& rViewEntry
)
168 { return this->renderComb( t
, rViewEntry
); } );
170 getScreenUpdater().notifyUpdate();
175 } // namespace slideshow::internal
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */