Get the style color and number just once
[LibreOffice.git] / slideshow / source / engine / transitions / figurewipe.cxx
blobf64145d5532ec72708d5c96ba366da5f73213e87
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/numeric/ftools.hxx>
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 #include "figurewipe.hxx"
28 namespace slideshow::internal {
30 ::basegfx::B2DPolyPolygon FigureWipe::operator () ( double t )
32 ::basegfx::B2DPolyPolygon res(m_figure);
33 res.transform(basegfx::utils::createScaleTranslateB2DHomMatrix(t, t, 0.5, 0.5));
34 return res;
37 std::shared_ptr<FigureWipe> FigureWipe::createTriangleWipe()
39 const double s60 = sin( basegfx::deg2rad(60.0) );
40 const double s30 = sin( basegfx::deg2rad(30.0) );
41 ::basegfx::B2DPolygon figure;
42 figure.append( ::basegfx::B2DPoint( 0.5 + s30, 0.5 ) );
43 figure.append( ::basegfx::B2DPoint( 0.0, -0.5 - s60 ) );
44 figure.append( ::basegfx::B2DPoint( -0.5 - s30, 0.5 ) );
45 figure.setClosed(true);
46 return std::make_shared<FigureWipe>(figure);
49 std::shared_ptr<FigureWipe> FigureWipe::createArrowHeadWipe()
51 const double s60 = sin( basegfx::deg2rad(60.0) );
52 const double s30 = sin( basegfx::deg2rad(30.0) );
53 const double off = s30;
54 ::basegfx::B2DPolygon figure;
55 figure.append( ::basegfx::B2DPoint( 0.5 + s30 + off, 0.5 + off ) );
56 figure.append( ::basegfx::B2DPoint( 0.0, -0.5 - s60 ) );
57 figure.append( ::basegfx::B2DPoint( -0.5 - s30 - off, 0.5 + off ) );
58 figure.append( ::basegfx::B2DPoint( 0.0, 0.5 ) );
59 figure.setClosed(true);
60 return std::make_shared<FigureWipe>(figure);
63 std::shared_ptr<FigureWipe> FigureWipe::createPentagonWipe()
65 const double s = sin( basegfx::deg2rad(18.0) );
66 const double c = cos( basegfx::deg2rad(18.0) );
67 ::basegfx::B2DPolygon figure;
68 figure.append( ::basegfx::B2DPoint( 0.5, 0.5 ) );
69 figure.append( ::basegfx::B2DPoint( 0.5 + s, 0.5 - c ) );
70 figure.append( ::basegfx::B2DPoint( 0.0, 0.5 - c - sin(basegfx::deg2rad(36.0)) ) );
71 figure.append( ::basegfx::B2DPoint( -0.5 - s, 0.5 - c ) );
72 figure.append( ::basegfx::B2DPoint( -0.5, 0.5 ) );
73 figure.setClosed(true);
74 return std::make_shared<FigureWipe>(figure);
77 std::shared_ptr<FigureWipe> FigureWipe::createHexagonWipe()
79 const double s = sin( basegfx::deg2rad(30.0) );
80 const double c = cos( basegfx::deg2rad(30.0) );
81 ::basegfx::B2DPolygon figure;
82 figure.append( ::basegfx::B2DPoint( 0.5, c ) );
83 figure.append( ::basegfx::B2DPoint( 0.5 + s, 0.0 ) );
84 figure.append( ::basegfx::B2DPoint( 0.5, -c ) );
85 figure.append( ::basegfx::B2DPoint( -0.5, -c ) );
86 figure.append( ::basegfx::B2DPoint( -0.5 - s, 0.0 ) );
87 figure.append( ::basegfx::B2DPoint( -0.5, c ) );
88 figure.setClosed(true);
89 return std::make_shared<FigureWipe>(figure);
92 std::shared_ptr<FigureWipe> FigureWipe::createStarWipe( sal_Int32 nPoints )
94 const double v = M_PI / nPoints;
95 const ::basegfx::B2DPoint p_( 0.0, -M_SQRT2 );
96 ::basegfx::B2DPolygon figure;
97 for ( sal_Int32 pos = 0; pos < nPoints; ++pos ) {
98 const double w = pos * 2.0 * M_PI / nPoints;
99 ::basegfx::B2DHomMatrix aTransform;
100 ::basegfx::B2DPoint p(p_);
101 aTransform.rotate( -w );
102 p *= aTransform;
103 figure.append(p);
104 p = p_;
105 aTransform.identity();
106 aTransform.scale( 0.5, 0.5 );
107 aTransform.rotate( -w - v );
108 p *= aTransform;
109 figure.append(p);
111 figure.setClosed(true);
112 return std::make_shared<FigureWipe>(figure);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */