LibreOffice Module slideshow (master) 1
clippingfunctor.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#include "clippingfunctor.hxx"
23
28
29namespace slideshow::internal
30{
32 const TransitionInfo& rTransitionInfo,
33 bool bDirectionForward,
34 bool bModeIn ) :
35 mpParametricPoly( rPolygon ),
36 maStaticTransformation(),
37 mbForwardParameterSweep( true ),
38 mbSubtractPolygon( false ),
39 mbScaleIsotrophically( rTransitionInfo.mbScaleIsotrophically ),
40 mbFlip(false)
41 {
42 ENSURE_OR_THROW( rPolygon,
43 "ClippingFunctor::ClippingFunctor(): Invalid parametric polygon" );
44
45 // maBackgroundRect serves as the minuent when
46 // subtracting a given clip polygon from the
47 // background. To speed up the clipper algo, avoid
48 // actual intersections of the generated
49 // poly-polygon with the minuent - i.e. choose the
50 // polygon to subtract from sufficiently large.
51
52 // blow up unit rect to (-1,-1),(2,2)
53 // AW: Not needed, just use range
54 // ::basegfx::B2DHomMatrix aMatrix;
55 // aMatrix.scale(3.0,3.0);
56 // aMatrix.translate(-1.0,-1.0);
57 // maBackgroundRect.transform( aMatrix );
58
59 // extract modification info from maTransitionInfo
60
61
62 // perform general transformations _before_ the reverse
63 // mode changes. This allows the Transition table to be
64 // filled more consistently (otherwise, when e.g. rotating
65 // a clip 90 degrees, the ReverseMethod::FlipX becomes
66 // ReverseMethod::FlipY instead)
67 if (rTransitionInfo.mnRotationAngle != 0.0 ||
68 rTransitionInfo.mnScaleX != 1.0 ||
69 rTransitionInfo.mnScaleY != 1.0)
70 {
72 // apply further transformations:
73 if (rTransitionInfo.mnRotationAngle != 0.0)
74 {
76 basegfx::deg2rad(rTransitionInfo.mnRotationAngle) );
77 }
78 if (rTransitionInfo.mnScaleX != 1.0 ||
79 rTransitionInfo.mnScaleY != 1.0)
80 {
82 rTransitionInfo.mnScaleX,
83 rTransitionInfo.mnScaleY );
84 }
86 }
87
88 if( !bDirectionForward )
89 {
90 // Client has requested reversed
91 // direction. Apply TransitionInfo's choice
92 // for that
93 switch( rTransitionInfo.meReverseMethod )
94 {
95 default:
97 false,
98 "TransitionFactory::TransitionFactory(): Unexpected reverse method" );
99 break;
100
102 break;
103
107 break;
108
112 break;
113
117 mbFlip = true;
118 break;
119
123 mbFlip = true;
124 break;
125 }
126 }
127
128 if( !bModeIn )
129 {
130 // client has requested 'out' mode. Apply
131 // TransitionInfo's method of choice
132 if( rTransitionInfo.mbOutInvertsSweep )
134 else
136 }
137 }
138
140 const ::basegfx::B2DSize& rTargetSize )
141 {
142 // modify clip polygon according to static
143 // transformation plus current shape size
145
146 // retrieve current clip polygon
147 ::basegfx::B2DPolyPolygon aClipPoly = (*mpParametricPoly)(
149
150 // TODO(Q4): workaround here, better be fixed in cppcanvas
151 if (aClipPoly.count() == 0)
152 aClipPoly.append( basegfx::B2DPolygon() );
153
154 if (mbFlip)
155 aClipPoly.flip();
156
158 {
159 // subtract given polygon from background
160 // rect. Do that before any transformations.
161
162 // calc maBackgroundRect \ aClipPoly
163 // =================================
164
165 // AW: Simplified
166 // use a range with fixed size (-1,-1),(2,2)
167 const basegfx::B2DRange aBackgroundRange(-1, -1, 2, 2);
168 const basegfx::B2DRange aClipPolyRange(aClipPoly.getB2DRange());
169
170 if(aBackgroundRange.isInside(aClipPolyRange))
171 {
172 // combine polygons; make the clip polygon the hole
173 aClipPoly = ::basegfx::utils::correctOrientations(aClipPoly);
174 aClipPoly.flip();
175 aClipPoly.insert(0, basegfx::utils::createPolygonFromRect(aBackgroundRange));
176 }
177 else
178 {
179 // when not completely inside aBackgroundRange clipping is needed
180 // subtract aClipPoly from aBackgroundRange
181 const basegfx::B2DPolyPolygon aBackgroundPolyPoly(basegfx::utils::createPolygonFromRect(aBackgroundRange));
182 aClipPoly = basegfx::utils::solvePolygonOperationDiff(aBackgroundPolyPoly, aClipPoly);
183 }
184 }
185
186 // scale polygon up to current shape size
188 {
189 const double nScale( ::std::max( rTargetSize.getWidth(),
190 rTargetSize.getHeight() ) );
191 aMatrix.scale( nScale, nScale );
192 aMatrix.translate( -(nScale - rTargetSize.getWidth())/2.0,
193 -(nScale - rTargetSize.getHeight())/2.0 );
194 }
195 else
196 {
197 aMatrix.scale( rTargetSize.getWidth(),
198 rTargetSize.getHeight() );
199 }
200
201 // apply cumulative transformation to clip polygon
202 aClipPoly.transform( aMatrix );
203
204 return aClipPoly;
205 }
206
207}
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void rotate(double fRadiant)
void translate(double fX, double fY)
void scale(double fX, double fY)
void insert(sal_uInt32 nIndex, const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void transform(const basegfx::B2DHomMatrix &rMatrix)
B2DRange getB2DRange() const
sal_uInt32 count() const
bool isInside(const Tuple2D< TYPE > &rTuple) const
ClippingFunctor(const ParametricPolyPolygonSharedPtr &rPolygon, const TransitionInfo &rTransitionInfo, bool bDirectionForward, bool bModeIn)
::basegfx::B2DHomMatrix maStaticTransformation
::basegfx::B2DPolyPolygon operator()(double nValue, const ::basegfx::B2DSize &rTargetSize)
Generate clip polygon.
#define ENSURE_OR_THROW(c, m)
sal_Int16 nValue
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DHomMatrix createRotateAroundPoint(double fPointX, double fPointY, double fRadiant)
B2DPolyPolygon solvePolygonOperationDiff(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
constexpr double deg2rad(double v)
::std::shared_ptr< ParametricPolyPolygon > ParametricPolyPolygonSharedPtr
@ Rotate180
Reverse by rotating polygon 180 degrees.
@ FlipX
Reverse by flipping polygon at the y (!) axis.
@ FlipY
Reverse by flipping polygon at the x (!) axis.
@ SubtractAndInvert
Combination of ReverseMethod::InvertSweep and ReverseMethod::SubtractPolygon.
@ Ignore
Ignore direction attribute altogether (if it has no sensible meaning for this transition)
bool mbOutInvertsSweep
When true, transition 'out' effects are realized by inverting the parameter sweep direction (1->0 ins...
double mnScaleX
X scaling of clip polygon (negative values mirror)
double mnRotationAngle
Rotation angle of clip polygon.
double mnScaleY
Y scaling of clip polygon (negative values mirror)
ReverseMethod meReverseMethod
Indicating the method to use when transition should be 'reversed'.