LibreOffice Module slideshow (master) 1
spiralwipe.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
21#include "spiralwipe.hxx"
22#include "transitiontools.hxx"
23
28
29
30namespace slideshow::internal {
31
32SpiralWipe::SpiralWipe( sal_Int32 nElements, bool flipOnYAxis )
34 m_sqrtElements( static_cast<sal_Int32>(
35 sqrt( static_cast<double>(nElements) ) ) ),
36 m_flipOnYAxis(flipOnYAxis)
37{
38}
39
41{
42 const double area = t * m_elements;
43 const double e = sqrt(area) / 2.0;
44 const sal_Int32 edge = static_cast<sal_Int32>(e) * 2;
45
47 const double edge_ = ::basegfx::pruneScaleValue(
48 static_cast<double>(edge) / m_sqrtElements );
49 aTransform.scale( edge_, edge_ );
50 aTransform.translate( 0.5, 0.5 );
52 poly.transform( aTransform );
54
55 if (! ::basegfx::fTools::equalZero( 1.0 - t )) {
56 const sal_Int32 edge1 = edge + 1;
57 sal_Int32 len = static_cast<sal_Int32>( (e - (edge /2)) * edge1 * 4 );
58 double w = M_PI_2;
59 while (len > 0) {
60 const sal_Int32 alen = std::min(len, edge1);
61 len -= alen;
62 poly = createUnitRect();
64 ::basegfx::pruneScaleValue( static_cast<double>(alen) / m_sqrtElements ),
65 ::basegfx::pruneScaleValue( 1.0 / m_sqrtElements ) );
66 aTransform.translate(
67 - ::basegfx::pruneScaleValue(
68 static_cast<double>(edge / 2) / m_sqrtElements ),
69 ::basegfx::pruneScaleValue(
70 static_cast<double>(edge / 2) / m_sqrtElements ) );
71 aTransform.rotate( w );
72 w -= M_PI_2;
73 aTransform.translate( 0.5, 0.5 );
74 poly.transform( aTransform );
75 res.append(poly);
76 }
77 }
78
79 return res;
80}
81
83{
85 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
86 innerSpiral.flip();
87 res.append(innerSpiral);
88 return m_flipOnYAxis ? flipOnYAxis(res) : res;
89}
90
92{
94 ::basegfx::B2DPolyPolygon innerSpiral( calcNegSpiral( 1.0 - t ) );
95 innerSpiral.flip();
96
97 if (m_fourBox) {
98 ::basegfx::B2DHomMatrix aTransform;
99 aTransform.scale( 0.5, 0.5 );
100 innerSpiral.transform( aTransform );
101 res.append(innerSpiral);
102 res.append( flipOnXAxis(innerSpiral) );
103 innerSpiral = flipOnYAxis(innerSpiral);
104 res.append(innerSpiral);
105 res.append( flipOnXAxis(innerSpiral) );
106 }
107 else {
108 ::basegfx::B2DHomMatrix aTransform;
109 aTransform.scale( 1.0, 0.5 );
110 innerSpiral.transform( aTransform );
111 res.append(innerSpiral);
112 res.append( flipOnXAxis(innerSpiral) );
113 }
114
115 return m_flipOnYAxis ? flipOnYAxis(res) : res;
116}
117
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
void rotate(double fRadiant)
void translate(double fX, double fY)
void scale(double fX, double fY)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void transform(const basegfx::B2DHomMatrix &rMatrix)
virtual ::basegfx::B2DPolyPolygon operator()(double t) override
Retrieve the poly-polygon for value t.
Definition: spiralwipe.cxx:91
SpiralWipe(sal_Int32 nElements, bool flipOnYAxis=false)
Definition: spiralwipe.cxx:32
virtual ::basegfx::B2DPolyPolygon operator()(double t) override
Retrieve the poly-polygon for value t.
Definition: spiralwipe.cxx:82
::basegfx::B2DPolyPolygon calcNegSpiral(double t) const
Definition: spiralwipe.cxx:40
sal_Int32 nElements
B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
::basegfx::B2DPolyPolygon flipOnYAxis(::basegfx::B2DPolyPolygon const &polypoly)
Flips on Y-axis:
::basegfx::B2DPolyPolygon flipOnXAxis(::basegfx::B2DPolyPolygon const &polypoly)
Flips on X-axis:
::basegfx::B2DPolygon createUnitRect()
Create a unit rect.
sal_Int32 w
std::vector< ElementEntry > m_elements